Giter VIP home page Giter VIP logo

luabindj's Introduction

luabindj

luabindj is a simple,easy to use lua binding in java.

Quick sample:

package org.netroc.luabindj.test;

	import org.luaj.vm2.LuaValue;
	import org.netroc.luabindj.LuaBindJ;
	import org.netroc.luabindj.LuaExport;
	
	public class MainClass {
		static class TestClass{
			@LuaExport
			public Integer n = 100;
			
			@LuaExport
			public int nn = 200;
	
			@LuaExport
			public Float ff = 300.20f;
	
			@LuaExport
			public TestClass child;
	
			public int add(int data) {
				return n + data;
			}
	
			@LuaExport
			public double lParam( int a, float b, double c, Integer d, int e) {
				return a+b+c+d+e;
			}
	
			@LuaExport
			public TestClass create() {
				return new TestClass();
			}
			
			@LuaExport
			public static String staticFunc() {
				return "staticFunc111";
			}
	
			@LuaExport
			public TestClass[] getArray() {
				TestClass[] arr = new TestClass[3];
				arr[0] = new TestClass();
				arr[0].n = 11111;
				arr[1] = new TestClass();
				arr[2] = new TestClass();
				return arr;
			}
		}
		
		public static void main(String[] args) {
			LuaBindJ lua = new LuaBindJ();
			
			LuaBindJ.registerClass(TestClass.class, "TestClass", true);
			
			lua.open();
			lua.openLibs();
			
			TestClass t = new TestClass();
			LuaValue val = LuaBindJ.toLuaValue(t);
			
			lua.addGlobal("obj", val);
			
			lua.runScript("oo={aa=1,bb=2}");
			
			lua.runScript("function pp( p1, p2) \n print(p1..p2) \n return p1..p2\n end");
			try {
				lua.call("pp", "13213", "aadsada");
			} catch (Exception e) {
				e.printStackTrace();
			}
			lua.runScript("print(obj:add(3))");
			
			//lua.runScript("obj.child = obj:create() \n print (obj.child.n..0.3)");
			//lua.runScript("print(obj.child.nn)");
			
			//lua.runScript("print(TestClass.staticFunc())");
			
			//lua.runScript("print(obj.child:getArray()[1].n, obj.child:getArray()[2].n, obj.child:getArray()[3].n)");
			
			System.out.print(t.n);
			
			lua.addGlobal("obj", LuaValue.NIL);
	}
}

License

luabindj is distributed with an MIT License.

luabindj's People

Contributors

cc682 avatar

Watchers

James Cloos avatar JJX 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.