I want to compile a code written in a programming language with static semantics targetting an unique Lua equivalent optimized code (of preference, compatible with Lua 5.1/5.2). So I need a compiler or tool that does this for me.
The reason I need this is because I want to execute a Lua code in a Flash game ("Transformice"). In this game, they implement Lua in server-side using LuaJ (it is written in Java) and LuaJ isn't like LuaJIT, which optimizes tables with inline caching and etc.. Unique thing I can do is open the Lua window (send /lua
in game chat) and execute my code there in tribe house.
The language must at least contain classes with consecutive members (like C++ struct
/class
, Java
, etc.), functions, interface for acessing tables (including the table length) and the Lua environment table (which in Lua 5.1 is _G
, _ENV
) and an entry execution (e.g., a main function).
The language will be pratically strongly/statically typed, because the classes will have members with static name, e.g., class A { A parent; }
(where Parent
is an instance member and is accessed like a[1]
), and it should be possible to assign nil
to everything of type A
.
Also, the compiler must be careful when code is assigning nil
to something, because generally this nil
may break the length of arrays in different Lua run times — please assign nil
as another value like false
whenever possible.
The equivalent Lua code must generally use arrays for representing instances of classes, like this...
Code example
(Entry file to compile.)
#include <debug>
struct Ball
{
int Weight;
Ball() : Weight(15);
};
void main()
{
Ball b = Ball();
trace(b.Weight); // Printing 15
}
(Compiler Output.)
local print = print;
local function Ball()
return { 15 };
end
local function main()
local b = Ball();
print(b[1]); -- trace(b.Weight);
end
main();