Original Post
Hello,
I want to expose an API of my game engine ( a collection of some of it's methods ) to Lua, using Luaj. I've been following the documentation here on the page for the class LibFunction, in order to create the library that will serve the collection of methods to lua. Here is the current code to my library of methods I want to expose to lua...
I have a Lua script file, named GameStateTransitions.lua, that wishes to use this library class's methods. Here the script's code.
I run the this script elsewhere in my engine like so.
However, I get this error.
I want to expose an API of my game engine ( a collection of some of it's methods ) to Lua, using Luaj. I've been following the documentation here on the page for the class LibFunction, in order to create the library that will serve the collection of methods to lua. Here is the current code to my library of methods I want to expose to lua...
...
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Varargs;
import org.luaj.vm2.lib.VarArgFunction;
public class VoidEngineAPI extends VarArgFunction
{
public VoidEngineAPI()
{
}
@Override
public LuaValue invoke(Varargs args)
{
switch ( opcode )
{
case 0:
{
LuaValue t = tableOf();
this.bind(t, VoidEngineAPI.class, new String[] { "vdTest"}, 1 );
env.set("VoidEngineAPI", t);
return t;
}
case 1: return valueOf("Lua, called a method from the Engine");
default: return error("bad opcode: "+opcode);
}
}
}
I have a Lua script file, named GameStateTransitions.lua, that wishes to use this library class's methods. Here the script's code.
vel = require('VoidEngineAPI')
print( 'vel', vel )
print( 'VoidEngineAPI', VoidEngineAPI )
for k,v in pairs(vel) do
print( 'k,v', k,v )
endI run the this script elsewhere in my engine like so.
LuaValue _G = JsePlatform.standardGlobals();
_G.get("dofile").call( LuaValue.valueOf(pathname));
However, I get this error.
module 'VoidEngineAPI' not found: VoidEngineAPI
no field package.preload['VoidEngineAPI']
'VoidEngineAPI.lua': cannot open VoidEngineAPI.lua: No such file or directory
no class 'VoidEngineAPI'
[/quote]
I really appreciate any ideas or help!!
Thanks!