Why do you need Lua?
Lua is a powerful, fast, lightweight, embeddable scripting language. It combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is ideal for configuration, scripting, and rapid prototyping. Lua is extremely popular among game developers.
Introduction to LuaAlchemy
Lua has been ported from C++ to Flash Platform with Crossbridge compiler. So, you can download the latest swc file here and connect it to your project. Now, you can create a main LuaAlchemy object.
With LuaAlchemy object you can:
– Define global Lua and as3 variables
– Synchronously call a global Lua function
– Supply a ByteArray as a file in Lua
– Run Lua scripts from strings
– Run Lua scripts from virtual file system
Lua virtual file system
Also, often you need to use a lua virtual file system, where you can store your assets, lua scripts and access to it through lua functions like loadfile(), dofile(), require() you can read more about it here(CoreLuaLibraries) and here(AutoAssets). I will provide a simple example which explains how to do that inside as3.
Let’s write a simple Lua file and write/embed it in luaBytes ByteArray in as3 for the next usage
-- Lets write global lua string foo and print it foo = "loaded" print(foo)
var lua:LuaAlchemy = new LuaAlchemy(); //place lua file in virtualFilesystemRoot default is "builtin://" lua.supplyFile("builtin://test.lua", luaBytes); //you can run it lua.doFile("builtin://test.lua");//trace loaded //you can access this file through lua script //so lets run a simple lua code lua.doString('dofile("test.lua")');//trace loaded //foo is global, so you can access it like that from different lua code lua.doString("print(foo)");//trace loaded
I think it’s really great to have a such nice opportunity to use Lua in Flash Platform, because now you can easily equip your game tools with Lua script support!
P.S. it was really surprising for me to know that you can extend Adobe Photoshop Lightroom with Lua