LASM - An Assembly Language for the Lua Virtual Machine
I'm sure many of us know that lua runs in a virtual machine via bytecode. You can get bytecode for a function by using string.dump(func). This is nice because you can compile Lua code into bytecode and save the bytecode instead of the source.
LASM is an assembly language for this bytecode. It's entire purpose is to allow the direct programming of Lua bytecode. On the surface, this isn't so useful. But theoretically, this could be useful in creating any new languages. It's much easier to target an assembly language in a compiler than it is to target Lua itself.
I'm not the first to create a LASM assembler for Lua, but I am the first to make one that's compatible with LuaJ and CC. And I think mine's pretty nice.
Here is a large writeup on the Lua bytecode specification as it stands today. The syntax used in their examples isn't exactly like my LASM implementation's syntax, but it's close.
Writing Your First LASM Program
Details of This LASM Language
Download: pastebin get ZghTBkmh lasm
Usage:
lasm [in file] [out file]
There is one little requirement though. LASM was designed with my Project NewLife in mind (which has been updated and now includes LASM), so it doesn't have any way of automatically making CraftOS able to run Lua bytecode files. So either at startup or at least before you try to run the output file, run the following code somehow.
function _G.loadfile(inFile) local data = {} local file = assert(fs.open(inFile,"rb")) for i = 1,fs.getSize(inFile)do data[i] = string.char(file.read()) end file.close() return loadstring(table.concat(data), fs.getName(inFile)) end