Giter Club home page Giter Club logo

hx-lua's Introduction

Note

This repo is forked from the original MattTuttle/hx-lua.

What's different: correctly supports both neko and cpp & added support to flash

The ndll's are not up-to-date. Run lime rebuild lua windows -clean to rebuild the ndll (replace windows with other platforms at will)

Run Lua code in Haxe

Run any Lua code inside Haxe on neko/cpp/flash targets. Has the option of passing a context object that will set variables before running the script.

var result = Lua.run("return true"); // returns a Bool to Haxe

Pass in values with a context object. The key names are used as variable names in the Lua script.

var result = Lua.run("if num > 14 then return 14 else return num end", {num: 15.3});

What if you want to call a function created in Haxe from Lua? Just pass the function in the context!

var result = Lua.run("return plus1(15)", { plus1: function(val:Int) { return val + 1; } });
if (result == 16)
	trace("success!");

Lua instances

It's possible to create multiple Lua instances to run scripts with different contexts/libraries.

var lua = new Lua();
lua.loadLibs(["base", "math"]);
lua.setVars({ myVar: 1 });
var result = lua.execute("return myVar");

Calling Lua functions

Calling global functions defined in lua can be done after executing a chunk of Lua code. You can either pass in a single value (for single argument functions) or an array (for multiple argument functions).

var lua = new Lua();
lua.execute("function add(a, b) return a + b end");
var result = lua.call("add", [1, 5]); // returns 6

hx-lua's People

Contributors

kevinresol avatar matttuttle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.