Framework for modding compiled classes with Lua using Haxe macros and LuaJIT.
Install LuaJIT backend using:
haxelib git linc_luajit https://github.com/AndreiRudenko/linc_luajit
(or ideally my fork of it)
haxelib git linc_luajit https://github.com/Snirozu/linc_luajit
And then lumod using:
haxelib install lumod
Then you can use lumod.LuaScriptClass.build("script.lua") build macro in your project in any class.
Every non-static function calls it's Lua script counterpart before it's code (lua function: function), and after it's code (lua function: function_post).
The first Lua function's value is stored in a local function variable called luaValue, this can be used optionally for aborting functions etc.
close()- Closes current Lua script.getProperty(name)- Gets a property from some class, by default it's the current haxe instance of current script. For example you can get the window of HaxeFlixel's game's width withgetProperty("flixel.FlxG.width").setProperty(name, value)- Basically works the same as thegetPropertyfunction but sets a value instead of getting it.callFunction(function, arguments)- Retrieves the function with the same technique as thegetPropertyfunction but instead of getting the property, it calls it like a method. Example usage:callFunction("flixel.math.FlxMath.roundDecimal", [1.2485, 2]).hasField(name)- Checks if a property exists.isPropertyFunction(name)- Checks if a property is a function.isPropertyObject(name)- Checks if a property is a object.
lmCall(function, arguments)- Calls a Lua function from the loaded script and returns it's value.lmGet(variable)- Gets a global Lua variable from the loaded script and returns it's value.lmSet(variable, value)- Creates or sets a global Lua (and HScript) variable in the loaded script tovalue.lmAddCallback(name, callback)- Declares a new function in the Lua script with a callback tocallback.lmLoad()- Loads or reloads the Lua script instance.
To enable HScript use LUMOD_HSCRIPT Haxe Define in the project configuration.
haxeRun(code)- Runs Haxe code via HScript interpreter.haxeSet(variable, value)- Sets a property in a HScript interpreter to a value.haxeImport(class, ?as)- Imports a class to the HScript interpreter, ifasis specified, the class will be defined as the specified name.
hscriptSet(variable, value)- Sets a property in a HScript interpreter to a value.
Game.hx
@:build(lumod.LuaScriptClass.build()) // if `scriptPath` argument is not specified then it will set to "(Class name).lua"
class Game {
function create() {
Sys.println("create function");
}
}Game.lua
function create()
print("before create function")
end
function create_post()
print("after create function")
endOutput
> before create function
> create function
> after create function