Browse Source

Added section on bytecode precompilation to the scripting documentation page.
ScriptInstance sends an event when the script object is created, so that the attribute inspector can be refreshed in case attributes change.

Lasse Öörni 12 years ago
parent
commit
852047545e

+ 17 - 1
Bin/Data/Scripts/Editor/EditorNodeWindow.as

@@ -47,6 +47,7 @@ void CreateNodeWindow()
     SubscribeToEvent(nodeWindow.GetChild("CloseButton", true), "Released", "HideNodeWindow");
     SubscribeToEvent(nodeWindow.GetChild("NewVarDropDown", true), "ItemSelected", "CreateNewVariable");
     SubscribeToEvent(nodeWindow.GetChild("DeleteVarButton", true), "Released", "DeleteVariable");
+    SubscribeToEvent("ScriptObjectCreated", "HandleScriptObjectCreated");
 }
 
 void HideNodeWindow()
@@ -117,7 +118,7 @@ void UpdateAttributes(bool fullUpdate)
             if (selectedComponents.length <= 1)
                 componentTitle.text = "No component";
             else
-                componentTitle.text = selectedComponents.length + " components";            
+                componentTitle.text = selectedComponents.length + " components";
         }
         else
         {
@@ -285,3 +286,18 @@ void DeleteVariable(StringHash eventType, VariantMap& eventData)
     if (erased)
         UpdateAttributes(false);
 }
+
+void HandleScriptObjectCreated(StringHash eventType, VariantMap& eventData)
+{
+    Object@ sender = GetEventSender();
+    
+    for (uint i = 0; i < editComponents.length; ++i)
+    {
+        if (sender is editComponents[i])
+        {
+            // Update inspector fully, as attribute set might have changed
+            UpdateAttributes(true);
+            break;
+        }
+    }
+}

+ 8 - 0
Docs/Reference.dox

@@ -386,6 +386,14 @@ Much of the Urho3D classes are exposed to scripts, however things that require l
 
 Check the automatically built \ref ScriptAPI "Scripting API" documentation for the exact function signatures. Note that the API documentation can be regenerated to the Urho3D log file by calling \ref Script::DumpAPI "DumpAPI()" function on the Script subsystem or by using \ref Tools_ScriptCompiler "ScriptCompiler tool".
 
+\section Script_Bytecode Precompiling scripts to bytecode
+
+Instead of compiling scripts from source on-the-fly during startup, they can also be precompiled to bytecode, then loaded. Use the \ref Tools_ScriptCompiler "ScriptCompiler" utility for this. In this case the resource request has to be pointed to the compiled file, which by default has the .asc extension:
+
+\code
+ScriptFile* file = GetSubsystem<ResourceCache>()->GetResource<ScriptFile>("Scripts/MyScript.asc");
+\endcode
+
 \section Scripting_Limitations Limitations
 
 There are some complexities of the scripting system one has to watch out for:

+ 3 - 0
Engine/Script/ScriptInstance.cpp

@@ -138,6 +138,7 @@ void ScriptInstance::SetClassName(const String& className)
         return;
     
     ReleaseObject();
+    
     className_ = className;
     CreateObject();
     MarkNetworkUpdate();
@@ -380,6 +381,8 @@ void ScriptInstance::CreateObject()
         
         if (methods_[METHOD_START])
             scriptFile_->Execute(scriptObject_, methods_[METHOD_START]);
+        
+        SendEvent(E_SCRIPTOBJECTCREATED);
     }
     else
         LOGERROR("Failed to create object of class " + className_ + " from " + scriptFile_->GetName());

+ 5 - 0
Engine/Script/ScriptInstance.h

@@ -34,6 +34,11 @@ namespace Urho3D
 class Script;
 class ScriptFile;
 
+/// Script object created.
+EVENT(E_SCRIPTOBJECTCREATED, ScriptObjectCreated)
+{
+}
+
 /// Inbuilt scripted component methods.
 enum ScriptInstanceMethod
 {