|
|
@@ -1,5 +1,6 @@
|
|
|
$#include "File.h"
|
|
|
$#include "Node.h"
|
|
|
+$#include "LuaScriptInstance.h"
|
|
|
|
|
|
enum CreateMode
|
|
|
{
|
|
|
@@ -98,6 +99,12 @@ class Node : public Serializable
|
|
|
// template <class T> T* CreateComponent(CreateMode mode = REPLICATED, unsigned id = 0);
|
|
|
Component* CreateComponent(const String type, CreateMode mode = REPLICATED, unsigned id = 0);
|
|
|
|
|
|
+ int CreateScriptObject(const String scriptObjectType);
|
|
|
+ int CreateScriptObject(const String fileName, const String scriptObjectType);
|
|
|
+
|
|
|
+ int GetScriptObject() const;
|
|
|
+ int GetScriptObject(const String scriptObjectType) const;
|
|
|
+
|
|
|
unsigned GetID() const;
|
|
|
const String& GetName() const;
|
|
|
StringHash GetNameHash() const;
|
|
|
@@ -413,4 +420,156 @@ static int tolua_SceneLuaAPI_Node_GetComponent00(lua_State* tolua_S)
|
|
|
return 0;
|
|
|
#endif
|
|
|
}
|
|
|
+#define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateScriptObject00
|
|
|
+
|
|
|
+static int tolua_SceneLuaAPI_Node_CreateScriptObject00(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_isnoobj(tolua_S,3,&tolua_err)
|
|
|
+ )
|
|
|
+ goto tolua_lerror;
|
|
|
+ else
|
|
|
+#endif
|
|
|
+ {
|
|
|
+ Node* self = (Node*) tolua_tousertype(tolua_S,1,0);
|
|
|
+ const String scriptObjectType = ((const String) tolua_tourho3dstring(tolua_S,2,0));
|
|
|
+#ifndef TOLUA_RELEASE
|
|
|
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'NodeCreateScriptObject'", NULL);
|
|
|
+#endif
|
|
|
+ {
|
|
|
+ LuaScriptInstance* instance = self->CreateComponent<LuaScriptInstance>();
|
|
|
+ if (!instance)
|
|
|
+ lua_pushnil(tolua_S);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ instance->CreateObject(scriptObjectType);
|
|
|
+ // Push script object to Lua stack.
|
|
|
+ lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, instance->GetScriptObjectRef());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+#ifndef TOLUA_RELEASE
|
|
|
+ tolua_lerror:
|
|
|
+ tolua_error(tolua_S,"#ferror in function 'CreateScriptObject'.",&tolua_err);
|
|
|
+ return 0;
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
+#define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateScriptObject01
|
|
|
+
|
|
|
+static int tolua_SceneLuaAPI_Node_CreateScriptObject01(lua_State* tolua_S)
|
|
|
+{
|
|
|
+ tolua_Error tolua_err;
|
|
|
+ if (
|
|
|
+ !tolua_isusertype(tolua_S,1,"Node",0,&tolua_err) ||
|
|
|
+ !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
|
|
|
+ !tolua_isurho3dstring(tolua_S,3,0,&tolua_err) ||
|
|
|
+ !tolua_isnoobj(tolua_S,4,&tolua_err)
|
|
|
+ )
|
|
|
+ goto tolua_lerror;
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Node* self = (Node*) tolua_tousertype(tolua_S,1,0);
|
|
|
+ const String fileName = ((const String) tolua_tourho3dstring(tolua_S,2,0));
|
|
|
+ const String scriptObjectType = ((const String) tolua_tourho3dstring(tolua_S,3,0));
|
|
|
+#ifndef TOLUA_RELEASE
|
|
|
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'NodeCreateScriptObject'", NULL);
|
|
|
+#endif
|
|
|
+ {
|
|
|
+ LuaScriptInstance* instance = self->CreateComponent<LuaScriptInstance>();
|
|
|
+ if (!instance)
|
|
|
+ lua_pushnil(tolua_S);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ instance->CreateObject(fileName, scriptObjectType);
|
|
|
+ // Push script object to Lua stack.
|
|
|
+ lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, instance->GetScriptObjectRef());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+tolua_lerror:
|
|
|
+ return tolua_SceneLuaAPI_Node_CreateScriptObject00(tolua_S);
|
|
|
+}
|
|
|
+
|
|
|
+#define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetScriptObject00
|
|
|
+static int tolua_SceneLuaAPI_Node_GetScriptObject00(lua_State* tolua_S)
|
|
|
+{
|
|
|
+#ifndef TOLUA_RELEASE
|
|
|
+ tolua_Error tolua_err;
|
|
|
+ if (
|
|
|
+ !tolua_isusertype(tolua_S,1,"const Node",0,&tolua_err) ||
|
|
|
+ !tolua_isnoobj(tolua_S,2,&tolua_err)
|
|
|
+ )
|
|
|
+ goto tolua_lerror;
|
|
|
+ else
|
|
|
+#endif
|
|
|
+ {
|
|
|
+ const Node* self = (const Node*) tolua_tousertype(tolua_S,1,0);
|
|
|
+#ifndef TOLUA_RELEASE
|
|
|
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetScriptObject'", NULL);
|
|
|
+#endif
|
|
|
+ {
|
|
|
+ LuaScriptInstance* instance = self->GetComponent<LuaScriptInstance>();
|
|
|
+ if (!instance)
|
|
|
+ lua_pushnil(tolua_S);
|
|
|
+ else
|
|
|
+ lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, instance->GetScriptObjectRef());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+#ifndef TOLUA_RELEASE
|
|
|
+ tolua_lerror:
|
|
|
+ tolua_error(tolua_S,"#ferror in function 'GetScriptObject'.",&tolua_err);
|
|
|
+ return 0;
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
+#define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetScriptObject01
|
|
|
+static int tolua_SceneLuaAPI_Node_GetScriptObject01(lua_State* tolua_S)
|
|
|
+{
|
|
|
+ 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
|
|
|
+ {
|
|
|
+ const Node* self = (const Node*) tolua_tousertype(tolua_S,1,0);
|
|
|
+ const String scriptObjectType = ((const String) tolua_tourho3dstring(tolua_S,2,0));
|
|
|
+#ifndef TOLUA_RELEASE
|
|
|
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetScriptObject'", NULL);
|
|
|
+#endif
|
|
|
+ {
|
|
|
+ int scriptObjectRef = LUA_REFNIL;
|
|
|
+
|
|
|
+ PODVector<LuaScriptInstance*> instances;
|
|
|
+ self->GetComponents<LuaScriptInstance>(instances, false);
|
|
|
+
|
|
|
+ for (unsigned i = 0; i < instances.Size(); ++i)
|
|
|
+ {
|
|
|
+ if (instances[i]->GetScriptObjectType() == scriptObjectType)
|
|
|
+ {
|
|
|
+ scriptObjectRef = instances[i]->GetScriptObjectRef();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (scriptObjectRef = LUA_REFNIL)
|
|
|
+ lua_pushnil(tolua_S);
|
|
|
+ else
|
|
|
+ lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, scriptObjectRef);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+tolua_lerror:
|
|
|
+ return tolua_SceneLuaAPI_Node_GetScriptObject00(tolua_S);
|
|
|
+}
|
|
|
$}
|