[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: LuaPlus problem.
- From: "Phillip Jones" <zootlewurdle@...>
- Date: Tue, 20 Jan 2004 15:45:11 -0000
I couldn't find an answer to this in the archives...
I have a problem using LuaPlus to call a C++ class member function with
parameters from Lua Script.
e.g.,
class CMyClass
{
public:
virtual void SomeFunc( void )
{
//do stuff...
}
virtual void SomeOtherFunc( int i, float f, const
char * psMessage )
{
//do stuff...
}
};
int main( int argc, char * argv[] )
{
LuaStateOwner poState;
LuaObject oLuaGlobals = poState->GetGlobals();
CMyClass oTestObject;
LuaObject oLuaObject =
oLuaGlobals.CreateTable( "LuaTestObject" );
oLuaObject.RegisterEx( "SomeFunc", oTestObject,
CMyClass::SomeFunc );
oLuaObject.RegisterEx( "SomeOtherFunc", oTestObject,
CMyClass::SomeOtherFunc );
poState->DoFile( "test.lua" );
}
In "test.lua" I have:
LuaTestObject:SomeFunc()
LuaTestObject:SomeOtherFunc( 2, 3, "blah" )
The first line of Lua calls the correct function, as I'd expect.
The second line, however, generates the error:
test.lua:2: calling 'SomeOtherFunc' on bad self (bad argument)
It doesn't seem to matter what function parameters I try, none work.
I need to attach the function to the Lua table, not in global scope,
as I need to have multiple instances of the objects available to Lua.
I can't see what I've done wrong.
If anyone has any ideas I'd appreciate your input.
It's possibly also worth me pointing out that I need this for a cross
platform project (PC/XBox/PS2).
(Hopefully Outlook hasn't made a complete mess of the formatting of this
email,
apologies if it has).