background preloader

Lua

Facebook Twitter

Penlight Documentation. Purpose It is often said of Lua that it does not include batteries. That is because the goal of Lua is to produce a lean expressive language that will be used on all sorts of machines, (some of which don't even have hierarchical filesystems). The Lua language is the equivalent of an operating system kernel; the creators of Lua do not see it as their responsibility to create a full software ecosystem around the language. That is the role of the community. A principle of software design is to recognize common patterns and reuse them.

Penlight captures many such code patterns, so that the intent of your code becomes clearer. The default error handling policy follows that of the Lua standard libraries: if a argument is the wrong type, then an error will be thrown, but otherwise we return nil,message if there is a problem. By default, the error stacktrace starts with your code, since you are not usually interested in the internal details of the library. ??

To Inject or not to Inject? The Programming Language Lua. Lua 5.1 Reference Manual. By Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes Copyright © 2006–2012 Lua.org, PUC-Rio. Freely available under the terms of the Lua license. contents · index · other versions · english · português · español Lua is an extension programming language designed to support general procedural programming with data description facilities. Being an extension language, Lua has no notion of a "main" program: it only works embedded in a host client, called the embedding program or simply the host. Lua is free software, and is provided as usual with no guarantees, as stated in its license.

Like any other reference manual, this document is dry in places. This section describes the lexis, the syntax, and the semantics of Lua. The language constructs will be explained using the usual extended BNF notation, in which {a} means 0 or more a's, and [a] means an optional a. 2.1 – Lexical Conventions The following keywords are reserved and cannot be used as names: 2.2 – Values and Types. Unknown Worlds home page » UnknownWorlds. Busted : Elegant Lua unit testing, by Olivine-Labs. What's busted, precious? Busted is a unit testing framework with a focus on being easy to use. busted works with lua >= 5.1, moonscript, terra, and LuaJIT >= 2.0.0. busted test specs read naturally without being too verbose.

You can even chain asserts and negations, such as assert.not.equals. Nest blocks of tests with contextual descriptions using describe, and add tags to blocks so you can run arbitrary groups of tests. An extensible assert library allows you to extend and craft your own assert functions specific to your case with method chaining. A modular output library lets you add on your own output format, along with the default pretty and plain terminal output, JSON with and without streaming, and TAP-compatible output that allows you to run busted specs within most CI servers. Busted test.lua Usage Installation Install busted through Luarocks. You can also install the latest or a branch by cloning the busted repository, and running luarocks make from the directory. CLI: Running Busted. LuaRocks Wiki: LuaRocks. LuaFileSystem. Overview LuaFileSystem is a Lua library developed to complement the set of functions related to file systems offered by the standard Lua distribution. LuaFileSystem offers a portable way to access the underlying directory structure and file attributes.

LuaFileSystem is free software and uses the same license as Lua 5.x (MIT). Status Current version is 1.7.0. Download LuaFileSystem can be installed using LuaRocks: $ luarocks install luafilesystem Its source can be found at its Github page. History Version 1.7.0 [15/Sep/2017] symlinkattributes function now provides 'target' field, containing name of the file that the symlink points to. attributes, symlinkattributes, touch, mkdir, and rmdir functions now return system-dependent error code as the third value on error. Version 1.6.3 [15/Jan/2015] Lua 5.3 support. Version 1.6.2 [?? Full Lua 5.2 compatibility (with Lua 5.1 fallbacks) Version 1.6.1 [01/Oct/2012] fix build for Lua 5.2 Version 1.6.0 [26/Sep/2012] Version 1.5.0 [20/Oct/2009] Credits. Zeuxcg.org - Lua callstack with C++ debugger. 07 Nov 2010 Lua is a very popular scripting language in game development industry. Many games use Lua for various scripting needs (data representation, UI scripting, AI scripting), and some go as far as write the majority of the game in Lua.

At CREAT, we used Lua for all of UI scripting, and for AI and other game logic on some projects. And, well, there were times when the game crashed - and the callstack consisted mainly of Lua functions. While there are probably very few bugs in Lua library code, and the language is safe so you can’t get buffer overruns or other madness only via script code, script code itself is useless, because it can’t do any interaction with the outside world - user, world state, scoreboard servers, etc. So naturally there is a Lua binding for some C/C++ functions, so that scripts can call them. Now, if one of these functions crashes - for example, because they got invalid input data - how do we trace the problem back to the script code?

Use a stack dumping function. Programming Gems. WxLua - homepage. 果冻想. Lua IDE: Decoda. Today we are very pleased to announce that we’ve released Decoda, our Lua IDE (Integrated Development Environment) and debugger, as open source. You can get the latest version of the source from GitHub and the Windows installer from the download page. We created Decoda in 2007 just as we were starting work on Natural Selection 2 and getting our company off the ground. Since Natural Selection 2 uses Lua heavily we realized that a complete IDE with an integrated debugger would be critical. Although it was initially an internal tool, we quickly realized that other developers would benefit from Decoda as well. Today, after the successful launch of Natural Selection 2, we have the opportunity to re-evaluate our business strategy. We intend to keep on developing Decoda, but we are most excited about what *you* can do to help make it the best IDE out there!

Max. LuaJIT. LuaJIT is a Just-In-Time Compiler (JIT) for the Lua programming language. Lua is a powerful, dynamic and light-weight programming language. It may be embedded or used as a general-purpose, stand-alone language. LuaJIT is Copyright © 2005-2017 Mike Pall, released under the MIT open source license. Compatibility Overview LuaJIT has been successfully used as a scripting middleware in games, appliances, network and graphics apps, numerical simulations, trading platforms and many other specialty applications. LuaJIT has been in continuous development since 2005. For LuaJIT 2.0, the whole VM has been rewritten from the ground up and relentlessly optimized for performance.

An innovative trace compiler is integrated with advanced, SSA-based optimizations and highly tuned code generation backends. More ... Please select a sub-topic in the navigation bar to learn more about LuaJIT. 深入Lua-based GUI系統架構與實做細節 >> 猴子靈藥. 在前篇「使用Lua實做GUI系統的遊戲實例」中介紹了 Lua 於 GUI 系統的基本用法後,本文開始進入 GUI 的核心功能層面。 一般來說,有數種不同的架構方式能夠結合 Lua 與 C++ 實做 GUI 系統。 其一是將 Lua Script 當作純粹資料描述用的程式碼,僅儲存 UI Layout 相關的資料(如前篇文章所示),而由 C++ Code 掌控核心功能並且讀取 Lua Script 進行資料的處理。 其二則是於 C++ 端實做出一組完整的 UI Widget 類別,然後再將這組 Widget 的所有函式、甚至所有類別,註冊給 Lua 端自行呼叫使用。

另一種方法則是在 Lua Script 中包含資料描述以及核心功能,將 GUI 系統的全部相關功能全權交由 Lua 端處理。 而 C++ 端程式,則負責發送鍵盤與滑鼠的輸入訊息給 Lua 端程式,供 GUI 系統判斷各種 UI 事件。 最後再將測試的結果,傳回給 C++ 端程式進行後續判斷與處理。 本文將使用這一種架構來實做 Lua-based GUI 系統。 使用上述的架構,在 C++ 端只需要實現唯一一個類別:GuiManager,做為 Facade 介面與遊戲引擎的其他系統溝通。 對整個 Lua-based GUI 系統的架構有了基礎的概念,並且瞭解 GUI 系統的 C++ 端如何運作之後,接著先看看在遊戲中使用 GUI Script 的實例: Frame { name = "ingame", x = 0, y = 0, width = 20, height = 20, backdrop = "Image/bk.png", Button { name = "ingame_main", x = 0, y = 0, width = 15, height = 20, graphics = StandardButtonGraphics, mouse_up = function() Gui.ShowFrame("main_menu"); Core.SetGameState(GAME_PAUSE); end, }; } 上述這段程式碼,定義了一個名稱為 in_game 的 Frame 元件,位於螢幕座標 (0, 0) 的位置,長度與寬度的大小都是 20 個像素,背景圖片使用 Image/bk.png。 Lua源码剖析(一) - 但行好事 莫问前程 - ITeye博客. 先来看lua中值的表示方式。 #define TValuefields Value value; int tt typedef struct lua_TValue { TValuefields; } TValue; #define TValuefields Value value; int tt typedef struct lua_TValue { TValuefields; } TValue; 其中tt表示类型,value也就是lua中对象的表示。

Typedef union { GCObject *gc; void *p; lua_Number n; int b; } Value; typedef union { GCObject *gc; void *p; lua_Number n; int b; } Value; gc用于表示需要垃圾回收的一些值,比如string,table等等。 Tvalue这样表示会有空间的浪费.可是由于要完全符合c99,因此只能这么做.否则我们为了效率可以这么做.由于在大多数机器上,指针都是严格对齐(4或者8字节对齐).因此后面的2,3位就是0,因此我们可以将类型存储在这几位,从而极大地压缩了Value的大小. 更新:这里经的老朱同学的提醒,其实tvalue之所以不使用指针的后几位来存储类型,更重要的时候由于和c的交互.因为那样的话,我们就必须强制和lua交互的c模块也必须保持和我们一样的内存模型了. lua_state表示一个lua虚拟机,它是per-thread的,也就是一个协程(多个和lua交互的c程序,那自然也会有多个lua-state)一个lua_state,然后来看它的几个比较重要的域。

StkId top这个域表示在这个栈上的第一个空闲的slot。 在 lstrlib中,基本上所有的str函数都是首先调用luaL_checklstring来得到所需要处理的字符串然后再进行处理。 LuaL_checklstring 函数,这个函数只是简单的对lua_tolstring进行了一层简单的封装。 因此我们详细来看index2adr这个函数,这个函数目的很简单,就是通过索引得到对应的值的指针。 我们首先要知道在lua中,索引值可以为负数也可以为正数,当为负数的话,top为-1,当为正数第一个压入栈的元素为1,依此类推. 首先来看TSring: Live coding in Lua with ZeroBrane Studio - ZeroBrane. I was working on a lightweight Lua IDE for those who want to learn programming when I came across Bret Victor's Inventing On Principle and Kill Math projects. If you haven't seen them before, I recommend you spend a bit of time listening to his ideas about interactive design.

Just don't close this page and come back when you're done as I'll show you how you can do some of it with Lua scripts today. The core part of the message is that designers need an immediate connection to their creations and even a short update-run-use loop may be too long to explore a variety of different options, parameters, and their interactions. Sometimes the relations or dependencies between variables become more obvious when you not only have a way to interact with the object, but also control the interaction. The video shows how you can use live coding with different scripts running in ZeroBrane Studio (you may need to switch the video to 720p to make the text more readable). Coxpcall - Coroutine Safe xpcall and pcall. LuaDoc: Documentation Generator Tool for the Lua language.

Overview LuaDoc is a documentation generator tool for Lua source code. It parses the declarations and documentation comments in a set of Lua source files and produces a set of XHTML pages describing the commented declarations and functions. The output is not limited to XHTML. Other formats can be generated by implementing new doclets. The format of the documentation comments is also flexible and can be customized by implementing new taglets. Please refer to customizing section for further information. LuaDoc is free software and uses the same license as Lua. Status Current version is 3.0.1. Download LuaDoc can be downloaded from its Lua Forge page. Dependencies LuaDoc depends on two external packages: History Version 3.0.1 [17/Feb/2008] added support to @usage tags (thanks to Rafael Sabbagh Armony) makefile improved to follow kepler standards lualogging dependency is now optional added a rockspec file Version 3.0.0 [13/Aug/2007] update to Lua 5.1 major internal refactoring Version 2.0 [14/Aug/2002]

ZeroBrane Studio - Lua IDE/editor/debugger for Windows, Mac OSX, and Linux. WxWidgets: Cross-Platform GUI Library. Development blog: Fixing memory issues in Lua. Garbage collection can be both a blessing and a curse. On the one hand, it frees you from manually managing memory. This saves development time, reduces bugs, and avoids tricky decisions about objects' ownerships and lifetimes.

On the other hand, when you do run into memory issues (and you most likely will), they can be a lot harder to diagnose and fix, because you don't have detailed control over how memory is allocated and freed. In this post I'll show some techniques that you can use to address memory issues in Lua (and by extension, in other garbage collected languages).

All Lua memory issues essentially boil down to one of two things: Lua uses too much memory On consoles memory is a precious resource and sometimes Lua is just using too much of it. Garbage collection is taking too long Too much garbage collection is (not surprisingly) caused by having too much garbage. Let's look at each issue in turn and see how we can address it. 1. So how do we find out where the memory is going? 2. LuaStudio | Professional LuaIDE.