lua-users home
lua-l archive

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


Hello,
I am new to Lua/LuaPlus so this question may not be that difficult. I am trying to develop a scriptable GUI system using LuaPlus. My general plan of attack is to have a main "guiManager" that receives commands from lua via object dispatch functors. The guiManager's functors are being called, but it seems that I can't get the function arguments from the lua stack. Are there any differences for getting function arguments for functors versus directly registered functions?

In any case here is some example code, Lines of interest are commented in all caps.

// Here is the member function I want called ( clipped for clarity )
int CLuaGooeyManager::createNewContext( LuaState * luaState )
{
	WindowElement* temp(NULL);
	std::string name;
	LuaStack args(luaState); // grab the stack
	if( args[1].IsString() ) // !!! THIS TEST FAILS - THROWS ERROR
		name = args[1].GetString( ); // get the name
	else
		throw( createError(LuaScriptError) );

	if( !findElement(name, temp) )
	{
		m_currentWindow = new gooey::WindowElement( );
		m_currentWindow->setElementName( name );
		m_contexts[name] = m_currentWindow;
	}
	else
	{
		throw( createError(Generic) );
	}
	return( 0 );
}

-------------------------------------------------------------------
Here is how I register the functors, sorry about the squished lines
// Register Functors
LuaObject registerLuaGooeyCallbacks(CLuaGooeyManager& gooeyManager, LuaStateOwner& luaState, LuaObject& luaGooeyInterface )
{
luaGooeyInterface = luaState.Get()->GetGlobals().CreateTable("MultiObjectMetaTable");
luaGooeyInterface.SetObject("__index", luaGooeyInterface);
luaGooeyInterface.RegisterObjectFunctor("createNewContext", &CLuaGooeyManager::createNewContext);
// ... more functions
LuaObject GooeyContainer = luaState.Get()->BoxPointer( &gooeyManager );
GooeyContainer.SetMetaTable(luaGooeyInterface);
luaState.Get()->GetGlobals().SetObject("LuaGooey", GooeyContainer );
return( GooeyContainer );
}
--------------------------------------------------------------------
// Finally here is the main application
luaGooey::CLuaGooeyManager m_TheLuaGui;
LuaPlus::LuaStateOwner     m_luaState;
LuaPlus::LuaObject         m_GooeyPlaceHolder;
LuaPlus::LuaObject         m_LuaGooeyInterface;
// register objects
m_GooeyPlaceHolder = registerLuaGooeyCallbacks( m_TheLuaGui, m_luaState, m_LuaGooeyInterface );
// try to execute string
try{
	// CALL FUNCTOR WITH STRING ARGUMENT
	m_luaState.Get()->DoString( "LuaGooey:createNewContext('foo')"   )
catch( luaGooey::SLuaGuiError e )
{
	m_TheLuaGui.handleError( e );
}

----------------------------------------------------------------------
Thanks!
-Kat

--
Katherine A. Scott
Research Engineer
-----------------------------
Cybernet Systems Corporation
727 Airport Blvd.
Ann Arbor, MI 48108-1639 USA
-----------------------------
kscott@cybernet.com
(734) 668-2567 x 134
www.cybernet.com