mirror of https://github.com/axmolengine/axmol.git
issue #3956:Add the conversional functions which are used in the templates of lua binding-generator
This commit is contained in:
parent
3ff127cf92
commit
ba73217667
|
@ -194,6 +194,23 @@ extern bool luaval_to_ccvaluemap(lua_State* L, int lo, cocos2d::ValueMap* ret);
|
||||||
extern bool luaval_to_ccvaluemapintkey(lua_State* L, int lo, cocos2d::ValueMapIntKey* ret);
|
extern bool luaval_to_ccvaluemapintkey(lua_State* L, int lo, cocos2d::ValueMapIntKey* ret);
|
||||||
extern bool luaval_to_ccvaluevector(lua_State* L, int lo, cocos2d::ValueVector* ret);
|
extern bool luaval_to_ccvaluevector(lua_State* L, int lo, cocos2d::ValueVector* ret);
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
bool luaval_to_object(lua_State* L, int lo, const char* type, T** ret)
|
||||||
|
{
|
||||||
|
if(nullptr == L || lua_gettop(L) < lo)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!luaval_is_usertype(L, lo, type, 0))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
*ret = static_cast<T*>(tolua_tousertype(L, lo, 0));
|
||||||
|
|
||||||
|
if (nullptr == ret)
|
||||||
|
LUA_PRECONDITION(ret, "Invalid Native Object");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// from native
|
// from native
|
||||||
extern void point_to_luaval(lua_State* L,const Point& pt);
|
extern void point_to_luaval(lua_State* L,const Point& pt);
|
||||||
|
@ -276,4 +293,43 @@ void ccvalue_to_luaval(lua_State* L,const cocos2d::Value& inValue);
|
||||||
void ccvaluemap_to_luaval(lua_State* L,const cocos2d::ValueMap& inValue);
|
void ccvaluemap_to_luaval(lua_State* L,const cocos2d::ValueMap& inValue);
|
||||||
void ccvaluemapintkey_to_luaval(lua_State* L, const cocos2d::ValueMapIntKey& inValue);
|
void ccvaluemapintkey_to_luaval(lua_State* L, const cocos2d::ValueMapIntKey& inValue);
|
||||||
void ccvaluevector_to_luaval(lua_State* L, const cocos2d::ValueVector& inValue);
|
void ccvaluevector_to_luaval(lua_State* L, const cocos2d::ValueVector& inValue);
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void object_to_luaval(lua_State* L,const char* type, T* ret)
|
||||||
|
{
|
||||||
|
if(nullptr != ret)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
Because all override functions wouldn't be bound,so we must use `typeid` to get the real class name
|
||||||
|
*/
|
||||||
|
std::string hashName = typeid(*ret).name();
|
||||||
|
auto iter = g_luaType.find(hashName);
|
||||||
|
std::string className = "";
|
||||||
|
if(g_luaType.end() != iter)
|
||||||
|
{
|
||||||
|
className = iter->second.c_str();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
className = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
cocos2d::Object* dynObject = dynamic_cast<cocos2d::Object *>(ret);
|
||||||
|
if (nullptr != dynObject)
|
||||||
|
{
|
||||||
|
int ID = (int)(dynObject->_ID) ;
|
||||||
|
int* luaID = &(dynObject->_luaID);
|
||||||
|
toluafix_pushusertype_ccobject(L,ID, luaID, (void*)ret,className.c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tolua_pushusertype(L,(void*)ret,className.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif //__COCOS2DX_SCRIPTING_LUA_COCOS2DXSUPPORT_LUABAISCCONVERSIONS_H__
|
#endif //__COCOS2DX_SCRIPTING_LUA_COCOS2DXSUPPORT_LUABAISCCONVERSIONS_H__
|
||||||
|
|
Loading…
Reference in New Issue