lumod

Framework for modding Haxe classes with Lua at runtime!
https://github.com/Snirozu/Lumod

To install, run:

haxelib install lumod 2.2.0 

See using Haxelib in Haxelib documentation for more information.

README.md

Lumod

Framework for modding compiled classes with Lua using Haxe macros and LuaJIT.

Setup

Installing

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.

How Lumod works

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.

Pre-defined Functions

Lua Script

  • 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 with getProperty("flixel.FlxG.width").
  • setProperty(name, value) - Basically works the same as the getProperty function but sets a value instead of getting it.
  • callFunction(function, arguments) - Retrieves the function with the same technique as the getProperty function 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.

Haxe class

  • 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 to value.
  • lmAddCallback(name, callback) - Declares a new function in the Lua script with a callback to callback.
  • lmLoad() - Loads or reloads the Lua script instance.

Pre-defined Functions (HScript)

To enable HScript use LUMOD_HSCRIPT Haxe Define in the project configuration.

Lua Script

  • 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, if as is specified, the class will be defined as the specified name.

Haxe class

  • hscriptSet(variable, value) - Sets a property in a HScript interpreter to a value.

Print Example

Game.hx haxe @: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`
``` lua
function create()
    print("before create function")
end

function create_post()
    print("after create function")
end

Output

> before create function
> create function
> after create function
Contributors
Snirozu
Version
2.2.0
Published
3 weeks ago
Dependencies
License
Apache

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub