Procházet zdrojové kódy

For Component, Resource and UIElement always return concrete object type to Lua.

Aster@中国上海 před 11 roky
rodič
revize
ebd705d674

+ 6 - 0
Source/Engine/LuaScript/ToluaUtils.cpp

@@ -21,6 +21,7 @@
 //
 //
 
 
 #include "Precompiled.h"
 #include "Precompiled.h"
+#include "Object.h"
 #include "Ptr.h"
 #include "Ptr.h"
 #include "tolua++.h"
 #include "tolua++.h"
 #include "ToluaUtils.h"
 #include "ToluaUtils.h"
@@ -342,3 +343,8 @@ template<> int ToluaPushPODVector<RayQueryResult>(lua_State* L, void* data, cons
 {
 {
     return tolua_pushurho3dpodvectorusertype(L, *((const PODVector<RayQueryResult>*)data), "RayQueryResult");
     return tolua_pushurho3dpodvectorusertype(L, *((const PODVector<RayQueryResult>*)data), "RayQueryResult");
 }
 }
+
+void ToluaPushObject(lua_State*L, void* data, const char* type)
+{
+    tolua_pushusertype(L, data, data ? static_cast<Object*>(data)->GetTypeName().CString() : type);
+}

+ 3 - 0
Source/Engine/LuaScript/ToluaUtils.h

@@ -131,3 +131,6 @@ template<> int ToluaPushPODVector<PhysicsRaycastResult>(lua_State* L, void* data
 template<> int ToluaPushPODVector<PhysicsRaycastResult2D>(lua_State* L, void* data, const char* type);
 template<> int ToluaPushPODVector<PhysicsRaycastResult2D>(lua_State* L, void* data, const char* type);
 /// Push PODVector<RayQueryResult> to Lua as a table.
 /// Push PODVector<RayQueryResult> to Lua as a table.
 template<> int ToluaPushPODVector<RayQueryResult>(lua_State* L, void* data, const char* type);
 template<> int ToluaPushPODVector<RayQueryResult>(lua_State* L, void* data, const char* type);
+/// Push Object to Lua.
+void ToluaPushObject(lua_State*L, void* data, const char* type);
+

+ 0 - 38
Source/Engine/LuaScript/pkgs/Resource/ResourceCache.pkg

@@ -60,42 +60,4 @@ static File* ResourceCacheGetFile(ResourceCache* cache, const String& fileName)
 
 
     return file;
     return file;
 }
 }
-
-// Disable generated GetResource function.
-#define TOLUA_DISABLE_tolua_ResourceLuaAPI_ResourceCache_GetResource00
-
-static int tolua_ResourceLuaAPI_ResourceCache_GetResource00(lua_State* tolua_S)
-{
-#ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype(tolua_S,1,"ResourceCache",0,&tolua_err) ||
- !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
- !tolua_isurho3dstring(tolua_S,3,0,&tolua_err) ||
- !tolua_isboolean(tolua_S,4,1,&tolua_err) ||
- !tolua_isnoobj(tolua_S,5,&tolua_err)
- )
- goto tolua_lerror;
- else
-#endif
- {
-  ResourceCache* self = (ResourceCache*)  tolua_tousertype(tolua_S,1,0);
-  const String type = ((const String)  tolua_tourho3dstring(tolua_S,2,0));
-  const String name = ((const String)  tolua_tourho3dstring(tolua_S,3,0));
-  bool SendEventOnFailure = ((bool)  tolua_toboolean(tolua_S,4,true));
-#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetResource'", NULL);
-#endif
- {
-  Resource* tolua_ret = (Resource*)  self->GetResource(type,name,SendEventOnFailure);
-  tolua_pushusertype(tolua_S,(void*)tolua_ret,type.CString());
- }
- }
- return 1;
-#ifndef TOLUA_RELEASE
- tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'GetResource'.",&tolua_err);
- return 0;
-#endif
-}
 $}
 $}

+ 0 - 70
Source/Engine/LuaScript/pkgs/Scene/Node.pkg

@@ -212,76 +212,6 @@ static bool NodeSaveXML(const Node* node, File* file)
     return file ? node->SaveXML(*file) : false;
     return file ? node->SaveXML(*file) : false;
 }
 }
 
 
-// Disable generated CreateComponent function.
-#define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateComponent00
-
-static int tolua_SceneLuaAPI_Node_CreateComponent00(lua_State* tolua_S)
-{
-#ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype(tolua_S,1,"Node",0,&tolua_err) ||
- !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
- !tolua_isnumber(tolua_S,3,1,&tolua_err) ||
- !tolua_isnumber(tolua_S,4,1,&tolua_err) ||
- !tolua_isnoobj(tolua_S,5,&tolua_err)
- )
- goto tolua_lerror;
- else
-#endif
- {
-  Node* self = (Node*)  tolua_tousertype(tolua_S,1,0);
-  const String type = ((const String)  tolua_tourho3dstring(tolua_S,2,0));
-  CreateMode mode = ((CreateMode) (int)  tolua_tonumber(tolua_S,3,REPLICATED));
-  unsigned id = ((unsigned)  tolua_tonumber(tolua_S,4,0));
-#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CreateComponent'", NULL);
-#endif
- {
-  Component* tolua_ret = (Component*)  self->CreateComponent(type,mode,id);
-  tolua_pushusertype(tolua_S,(void*)tolua_ret,type.CString());
- }
- }
- return 1;
-#ifndef TOLUA_RELEASE
- tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'CreateComponent'.",&tolua_err);
- return 0;
-#endif
-}
-
-// Disable generated GetComponent function.
-#define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetComponent00
-static int tolua_SceneLuaAPI_Node_GetComponent00(lua_State* tolua_S)
-{
-#ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype(tolua_S,1,"const Node",0,&tolua_err) ||
- !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
- !tolua_isnoobj(tolua_S,3,&tolua_err)
- )
- goto tolua_lerror;
- else
-#endif
- {
-  const Node* self = (const Node*)  tolua_tousertype(tolua_S,1,0);
-  const String type = ((const String)  tolua_tourho3dstring(tolua_S,2,0));
-#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetComponent'", NULL);
-#endif
- {
-  Component* tolua_ret = (Component*)  self->GetComponent(type);
-  tolua_pushusertype(tolua_S,(void*)tolua_ret,type.CString());
- }
- }
- return 1;
-#ifndef TOLUA_RELEASE
- tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'GetComponent'.",&tolua_err);
- return 0;
-#endif
-}
 #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateScriptObject00
 #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateScriptObject00
 
 
 static int tolua_SceneLuaAPI_Node_CreateScriptObject00(lua_State* tolua_S)
 static int tolua_SceneLuaAPI_Node_CreateScriptObject00(lua_State* tolua_S)

+ 4 - 0
Source/Engine/LuaScript/pkgs/ToCppHook.lua

@@ -97,6 +97,10 @@ function post_output_hook(package)
     WRITE(result)
     WRITE(result)
 end
 end
 
 
+_push_functions['Component'] = "ToluaPushObject"
+_push_functions['Resource'] = "ToluaPushObject"
+_push_functions['UIElement'] = "ToluaPushObject"
+
 -- Is Urho3D Vector type.
 -- Is Urho3D Vector type.
 function urho3d_is_vector(t)
 function urho3d_is_vector(t)
     return t:find("Vector<") ~= nil
     return t:find("Vector<") ~= nil

+ 0 - 135
Source/Engine/LuaScript/pkgs/UI/UIElement.pkg

@@ -307,141 +307,6 @@ static bool UIElementSaveXML(const UIElement* element, const String& fileName)
     return element->SaveXML(file);
     return element->SaveXML(file);
 }
 }
 
 
-// Disable generated CreateChild function.
-#define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_CreateChild00
-
-static int tolua_UILuaAPI_UIElement_CreateChild00(lua_State* tolua_S)
-{
-#ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype(tolua_S,1,"UIElement",0,&tolua_err) ||
- !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
- !tolua_isurho3dstring(tolua_S,3,1,&tolua_err) ||
- !tolua_isnumber(tolua_S,4,1,&tolua_err) ||
- !tolua_isnoobj(tolua_S,5,&tolua_err)
- )
- goto tolua_lerror;
- else
-#endif
- {
-  UIElement* self = (UIElement*)  tolua_tousertype(tolua_S,1,0);
-  const String type = ((const String)  tolua_tourho3dstring(tolua_S,2,0));
-  const String name = ((const String)  tolua_tourho3dstring(tolua_S,3,String::EMPTY));
-  unsigned index = ((unsigned)  tolua_tonumber(tolua_S,4,M_MAX_UNSIGNED));
-#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CreateChild'", NULL);
-#endif
- {
-  UIElement* tolua_ret = (UIElement*)  self->CreateChild(type,name,index);
-  tolua_pushusertype(tolua_S,(void*)tolua_ret,type.CString());
- }
- }
- return 1;
-#ifndef TOLUA_RELEASE
- tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'CreateChild'.",&tolua_err);
- return 0;
-#endif
-}
-
-// Disable generated GetChild function.
-#define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_GetChild00
-
-static int tolua_UILuaAPI_UIElement_GetChild00(lua_State* tolua_S)
-{
-#ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype(tolua_S,1,"const UIElement",0,&tolua_err) ||
- !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
- !tolua_isboolean(tolua_S,3,1,&tolua_err) ||
- !tolua_isnoobj(tolua_S,4,&tolua_err)
- )
- goto tolua_lerror;
- else
-#endif
- {
-  const UIElement* self = (const UIElement*)  tolua_tousertype(tolua_S,1,0);
-  const String name = ((const String)  tolua_tourho3dstring(tolua_S,2,0));
-  bool recursive = ((bool)  tolua_toboolean(tolua_S,3,false));
-#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetChild'", NULL);
-#endif
- {
-  UIElement* tolua_ret = (UIElement*)  self->GetChild(name,recursive);
-  tolua_pushusertype(tolua_S,(void*)tolua_ret, tolua_ret ? tolua_ret->GetTypeName().CString() : "UIElement");
- }
- }
- return 1;
-#ifndef TOLUA_RELEASE
- tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'GetChild'.",&tolua_err);
- return 0;
-#endif
-}
-
-// Disable generated GetChild function.
-#define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_GetChild01
-
-static int tolua_UILuaAPI_UIElement_GetChild01(lua_State* tolua_S)
-{
- tolua_Error tolua_err;
- if (
- !tolua_isusertype(tolua_S,1,"const UIElement",0,&tolua_err) ||
- !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
- !tolua_isnoobj(tolua_S,3,&tolua_err)
- )
- goto tolua_lerror;
- else
- {
-  const UIElement* self = (const UIElement*)  tolua_tousertype(tolua_S,1,0);
-  unsigned index = ((unsigned)  tolua_tonumber(tolua_S,2,0));
-#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetChild'", NULL);
-#endif
- {
-  UIElement* tolua_ret = (UIElement*)  self->GetChild(index);
-  tolua_pushusertype(tolua_S,(void*)tolua_ret, tolua_ret ? tolua_ret->GetTypeName().CString() : "UIElement");
- }
- }
- return 1;
-tolua_lerror:
- return tolua_UILuaAPI_UIElement_GetChild00(tolua_S);
-}
-
-// Disable generated GetParent function */
-#define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_GetParent00
-
-static int tolua_UILuaAPI_UIElement_GetParent00(lua_State* tolua_S)
-{
-#ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype(tolua_S,1,"const UIElement",0,&tolua_err) ||
- !tolua_isnoobj(tolua_S,2,&tolua_err)
- )
- goto tolua_lerror;
- else
-#endif
- {
-  const UIElement* self = (const UIElement*)  tolua_tousertype(tolua_S,1,0);
-#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetParent'", NULL);
-#endif
- {
-  UIElement* tolua_ret = (UIElement*)  self->GetParent();
-  tolua_pushusertype(tolua_S,(void*)tolua_ret, tolua_ret ? tolua_ret->GetTypeName().CString() : "UIElement");
- }
- }
- return 1;
-#ifndef TOLUA_RELEASE
- tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'GetParent'.",&tolua_err);
- return 0;
-#endif
-}
-
 #define GetStyle GetAppliedStyle
 #define GetStyle GetAppliedStyle
 #define SetColorAttr SetColor
 #define SetColorAttr SetColor
 $}
 $}