本文整理汇总了C++中JObject::Clone方法的典型用法代码示例。如果您正苦于以下问题:C++ JObject::Clone方法的具体用法?C++ JObject::Clone怎么用?C++ JObject::Clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JObject
的用法示例。
在下文中一共展示了JObject::Clone方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FnCreate
int JLuaServer::FnCreate( lua_State* pLua )
{
int nParam = lua_gettop( pLua );
if (nParam < 1 || nParam > 3)
{
rlog.err( "LUA: Incorrect command usage: <create>. "
"Must be: create( <className or fileName> | <templateObject>, [<newName>, <parentObject>] )" );
lua_settop( pLua, 0 );
lua_pushnil( pLua );
return 1;
}
// first parameter
const char* pClassName = lua_tostring( pLua, 1 );
JObject* pTemplateObj = NULL;
if (!pClassName)
{
pTemplateObj = (JObject*)lua_touserdata( pLua, 1 );
}
// second parameter
const char* pObjName = lua_tostring( pLua, 2 );
// third parameter
JObject* pParentObj = NULL;
if (nParam > 2)
{
pParentObj = (JObject*)lua_touserdata( pLua, 3 );
}
else
{
JLuaThread* pThread = reinterpret_cast<JLuaThread*>( pLua->userdata );
assert( pThread->m_pLua == pLua );
pParentObj = pThread->m_pRootObj;
}
JObject* pObj = NULL;
if (pClassName)
{
pObj = g_pObjectServer->Create( pClassName );
// try to load from script
if (pObj == NULL)
{
pObj = g_pPersistServer->LoadObject( pClassName );
}
if (pObj == NULL)
{
rlog.err( "LUA: Cannot create an object because of unknown class (or filename): %s", pClassName );
lua_settop( pLua, 0 );
lua_pushnil( pLua );
return 1;
}
if (pObjName)
{
pObj->SetName( pObjName );
}
}
else if (pTemplateObj)
{
pObj = pTemplateObj->Clone( pParentObj, pObjName );
}
if (pParentObj)
{
pParentObj->AddChild( pObj );
}
lua_settop( pLua, 0 );
lua_pushlightuserdata( pLua, pObj );
return 1;
} // JLuaServer::FnCreate