本文整理汇总了C++中JObject::CallMethod方法的典型用法代码示例。如果您正苦于以下问题:C++ JObject::CallMethod方法的具体用法?C++ JObject::CallMethod怎么用?C++ JObject::CallMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JObject
的用法示例。
在下文中一共展示了JObject::CallMethod方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FnCall
int JLuaServer::FnCall( lua_State* pLua )
{
if (lua_gettop( pLua ) < 2 || lua_gettop( pLua ) > 3)
{
rlog.err( "LUA: Incorrect command usage: <call>. "
"Function takes 2 to 3 arguments (object|objectName, funcName, [tag]), but %d is provided", lua_gettop( pLua ) );
lua_settop( pLua, 0 );
return 0;
}
JObject* pObj = NULL;
const char* pPath = lua_tostring( pLua, 1 );
if (pPath)
{
JLuaThread* pThread = reinterpret_cast<JLuaThread*>( pLua->userdata );
assert( pThread->m_pLua == pLua );
JObject* pRootObj = pThread->m_pRootObj;
pObj = g_pObjectServer->FindObject( pPath, NULL, pRootObj );
if (!pObj)
{
rlog.warn( "LUA: Method <call> refers to non-existing object: %s", pPath );
return NULL;
}
}
else
{
pObj = reinterpret_cast<JObject*>( lua_touserdata( pLua, 1 ) );
if (!pObj)
{
rlog.warn( "LUA: Trying to call <call> for the nil object" );
return NULL;
}
}
const char* pMethodName = lua_tostring( pLua, 2 );
int tag = -1;
if (lua_isnumber( pLua, 3 ))
{
tag = (int)lua_tonumber( pLua, 3 );
}
bool bRes = pObj->CallMethod( pMethodName, tag );
if (!bRes)
{
rlog.err( "LUA: Could not call method '%s' for object '%s' of type '%s'.",
pMethodName, pObj->GetName(), pObj->ClassName() );
}
return 0;
} // JLuaServer::FnCall