javaandroid-studioluaj

Excute lua script in java


Iam trying to excute an lua script in android studio for this i used Luaj library from http://www.luaj.org/luaj/3.0/README.html? .

String script = "assets/hello.lua";
    Globals globals = JsePlatform.standardGlobals();
    LuaValue chunk = globals.loadfile(script);
    m.setText(chunk.call( LuaValue.valueOf(script) ).tojstring());

i used this my lua file is in assets i just put print("hello") in my lua file so i should get hello as result in my text view but i always get "nil" in my textview is there any solutions?


Solution

  • print("hello") prints "hello" and then returns nil. The value you get from chunk.call is what your Lua code returned, not what it printed.