SDK Question Registering a lua function with Orbiter

escapetomsfate

OBSP Developer
Addon Developer
Joined
Jun 21, 2008
Messages
282
Reaction score
0
Points
0
Location
GB
I want to register a function with Orbiter's lua interpreter so that it's recognised in scripts and in the lua console.

Code:
//simple lua function
static int Lua_function(lua_State* L)
{
        //just print to the screen to show that the function has been recognised
sprintf(oapiDebugString(), "LUA function recognised!");
	return 0;
}


//in the module's constructor, I assume that's the best place:
//register LUA functions
lua_register(oapiGetLua(oapiCreateInterpreter()), "function", Lua_function);

If I compile that code, and then input function() into the lua console, the function isn't recognised :(

I've probably misunderstood the purpose of oapiCreateInterpreter, I thought it returned a handle to the "global" interpreter.

Any help appreciated :) thanks.
 
Currently functions can only be added on a per-vessel-class basis, by overloading the VESSEL3::clbkGeneric method and intercepting the VMSG_LUAINTERPRETER and VMSG_LUAINSTANCE messages.

VMSG_LUAINTERPRETER is sent when an interpreter associated with the vessel is created. It can be used to set up the script environment for the vessel.

VMSG_LUAINSTANCE is sent when an existing interpreter creates a class instance of the vessel type. It can be used append methods to the vessel object's metatable.
 
No, it should be a new interpreter instance AFAIR.
 
Currently functions can only be added on a per-vessel-class basis, by overloading the VESSEL3::clbkGeneric method and intercepting the VMSG_LUAINTERPRETER and VMSG_LUAINSTANCE messages.

VMSG_LUAINTERPRETER is sent when an interpreter associated with the vessel is created. It can be used to set up the script environment for the vessel.

VMSG_LUAINSTANCE is sent when an existing interpreter creates a class instance of the vessel type. It can be used append methods to the vessel object's metatable.

:thankyou: for clearing that up! :)
 
Back
Top