lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> I have a problem using LuaPlus to call a C++ class member 
> function with parameters from Lua Script.
> 
> 		virtual	void	SomeOtherFunc( int i, float f, const
> char * psMessage )
> 		{
> 			//do stuff...
> 		}
> 
> int main( int argc, char * argv[] )
> {
> 	LuaStateOwner	poState;
> 	CMyClass		oTestObject;
> 	LuaObject		oLuaObject	=
> oLuaGlobals.CreateTable( "LuaTestObject" );
> 
> 	oLuaObject.RegisterEx( "SomeOtherFunc", oTestObject, 
> CMyClass::SomeOtherFunc );
> 
> 	poState->DoFile( "test.lua" );	
> }
> 
> In "test.lua" I have:
> 
> LuaTestObject:SomeOtherFunc( 2, 3, "blah" )

The : operator in Lua passes an implicit 'self'... in this case,
LuaTestObject.  It is syntactically equivalent to:

LuaTestObject.SomeOtherFunc( LuaTestObject, 2, 3, "blah" )

If your function is corrected to:

virtual void SomeOtherFunc( LuaObject o, int i, float f, const char *
psMessage )

Then the above will work.

But this still doesn't accomplish what you want based on this:

> 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 am releasing a standalone version of the internal LuaPlus Call Dispatcher
this evening.  It does not require a modified Lua interpreter as past
versions have, so it should be accessible to all (but is more convenient
with the real LuaPlus).  It also handles object dispatching, as you have
above.

I'll send it to you offline so you can peruse it before the release.

Josh


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.559 / Virus Database: 351 - Release Date: 1/7/2004