Browse Source

Update LuaIntegration sample.

aster2013 11 years ago
parent
commit
a2197916a7

+ 1 - 1
Source/Engine/LuaScript/LuaScriptInstance.cpp

@@ -267,7 +267,7 @@ bool LuaScriptInstance::CreateObject(const String& scriptObjectType)
 
 
 bool LuaScriptInstance::CreateObject(LuaFile* scriptFile, const String& scriptObjectType)
 bool LuaScriptInstance::CreateObject(LuaFile* scriptFile, const String& scriptObjectType)
 {
 {
-    SetScriptFile(0);
+    SetScriptFile(scriptFile);
     SetScriptObjectType(scriptObjectType);
     SetScriptObjectType(scriptObjectType);
     return scriptObjectRef_ != LUA_REFNIL;
     return scriptObjectRef_ != LUA_REFNIL;
 }
 }

+ 6 - 1
Source/Samples/22_LuaIntegration/LuaIntegration.cpp

@@ -26,6 +26,7 @@
 #include "Font.h"
 #include "Font.h"
 #include "Graphics.h"
 #include "Graphics.h"
 #include "Input.h"
 #include "Input.h"
+#include "LuaFile.h"
 #include "LuaFunction.h"
 #include "LuaFunction.h"
 #include "LuaScript.h"
 #include "LuaScript.h"
 #include "LuaScriptInstance.h"
 #include "LuaScriptInstance.h"
@@ -95,6 +96,10 @@ void LuaIntegration::CreateScene()
     zone->SetFogStart(10.0f);
     zone->SetFogStart(10.0f);
     zone->SetFogEnd(100.0f);
     zone->SetFogEnd(100.0f);
     
     
+    LuaFile* scriptFile = cache->GetResource<LuaFile>("LuaScripts/Rotator.lua");
+    if (!scriptFile)
+        return;
+
     // Create randomly positioned and oriented box StaticModels in the scene
     // Create randomly positioned and oriented box StaticModels in the scene
     const unsigned NUM_OBJECTS = 2000;
     const unsigned NUM_OBJECTS = 2000;
     for (unsigned i = 0; i < NUM_OBJECTS; ++i)
     for (unsigned i = 0; i < NUM_OBJECTS; ++i)
@@ -110,7 +115,7 @@ void LuaIntegration::CreateScene()
         // Add our custom Rotator script object (using the LuaScriptInstance C++ component to instantiate / store it) which will
         // Add our custom Rotator script object (using the LuaScriptInstance C++ component to instantiate / store it) which will
         // rotate the scene node each frame, when the scene sends its update event
         // rotate the scene node each frame, when the scene sends its update event
         LuaScriptInstance* instance = boxNode->CreateComponent<LuaScriptInstance>();
         LuaScriptInstance* instance = boxNode->CreateComponent<LuaScriptInstance>();
-        instance->CreateObject("LuaScripts/Rotator.lua", "Rotator");
+        instance->CreateObject(scriptFile, "Rotator");
         
         
         // Call the script object's "SetRotationSpeed" function.
         // Call the script object's "SetRotationSpeed" function.
         WeakPtr<LuaFunction> function = instance->GetScriptObjectFunction("SetRotationSpeed");
         WeakPtr<LuaFunction> function = instance->GetScriptObjectFunction("SetRotationSpeed");