2

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();
4
  • You wrote "a specific language": Is any language OK?
    – Nicolas Raoul
    Jul 5, 2017 at 6:18
  • @NicolasRaoul I need a language with fixed resources like classes, types, namespaces, etc., arrays that can be resized and providing interface for accessing the Lua environment table.
    – user31876
    Jul 5, 2017 at 12:50
  • Can it be Lua itself?
    – Nicolas Raoul
    Jul 5, 2017 at 14:47
  • @NicolasRaoul May... depending on what the compiler does.
    – user31876
    Jul 5, 2017 at 15:15

1 Answer 1

0
+50

(Since you wrote I need a language with fixed resources like classes, types, namespaces, etc., arrays that can be resized and providing interface for accessing the Lua environment table. I'm gonna go out on a limb and recommend this scripting lang to you.)

Angelscript has all the OOP features you want and claims it's "extremely flexible" so I'm fairly sure you can (with a bit of hacking) integrate it well with Lua's environment.

Angelscript does not provide dynamically sized arrays, but there is a plug-in for that.

Check out the rather impressive features here.

2
  • Nice, I've heard of it before. Though my question asks for a compiler targeting Lua code.
    – user31876
    Jul 8, 2017 at 12:05
  • 1
    Your comment says otherwise. I think you might be going about it the wrong way if you're asking this and commenting that. Look, why don't you say what the problem is you're trying to solve? Maybe there's a way out of this hellscape without adding more dependencies? On a side note: A little background info on the question is always a good idea. I usually include that in my questions.
    – Xunie
    Jul 8, 2017 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.