Hey guys!
I'm developing a module that allows you to put a fixed camera on an object. It's mainly for taking videos of launch (to get the same as a real launch kind of footage). Thus, I want to interface it with Lua script. It works fine without the Lua interface
The module basically allows you to create a camera vessel (just like FlyByOrbiter)
I followed the doc and created these methods to get the Lua's interface:
and:
Now, when i run in the Lua console:
I get "Execution Error"... I tried camAtlas:get_name() and it works just fine, so I've no idea of what's wrong with my piece of code. I run out of ideas, can you help me?
Thanks in advance,
Ludovic
I'm developing a module that allows you to put a fixed camera on an object. It's mainly for taking videos of launch (to get the same as a real launch kind of footage). Thus, I want to interface it with Lua script. It works fine without the Lua interface
The module basically allows you to create a camera vessel (just like FlyByOrbiter)
I followed the doc and created these methods to get the Lua's interface:
Code:
int CAMERA::clbkGeneric (int msgid, int prm, void *context)
{
switch (msgid) {
case VMSG_LUAINSTANCE:
return Lua_InitInstance (context);
}
return 0;
}
Code:
int CAMERA::Lua_InitInstance (void *context)
{
lua_State *L = (lua_State*)context;
// check if interpreter has DG table loaded already
luaL_getmetatable (L, "VESSEL.CAMERA");
if (lua_isnil (L, -1)) { // register new functions
lua_pop (L, 1);
static const struct luaL_reg dgLib[] = {
{"setTargetCamera", setTargetCamera},
{NULL, NULL}
};
// create metatable for vessel userdata
luaL_newmetatable (L, "CAMERA.vtable");
// create a table for the overloaded methods
luaL_openlib (L, "CAMERA.method", dgLib, 0);
// create metatable for accessing inherited methods from VESSEL
luaL_newmetatable (L, "CAMERA.base");
lua_pushstring (L, "__index");
luaL_getmetatable (L, "VESSEL.vtable");
lua_settable (L, -3);
// set DG.base as metatable for CAMERA.method
lua_setmetatable (L, -2);
// point vessel userdata to CAMERA.method
lua_pushstring (L, "__index");
lua_pushvalue (L, -2); // push CAMERA.method
lua_settable (L, -4);
// pop CAMERA.method from the stack
lua_pop (L, 1);
}
lua_setmetatable (L, -2);
return 0;
}
and:
Code:
static int setTargetCamera (lua_State *L)
{
return 0;
}
Now, when i run in the Lua console:
Code:
camAtlas=vessel.get_interface('cameraAtlasV')
camAtlas:setTargetCamera()
I get "Execution Error"... I tried camAtlas:get_name() and it works just fine, so I've no idea of what's wrong with my piece of code. I run out of ideas, can you help me?
Thanks in advance,
Ludovic