/// <summary> /// Initialises the Lua environment and compiles the Lua string for execution later on. /// </summary> protected virtual void InitLuaScript() { if (initialised) { return; } if (luaEnvironment == null) { // Create a Lua Environment if none exists yet luaEnvironment = LuaEnvironment.GetLua(); } if (luaEnvironment == null) { Debug.LogError("No Lua Environment found"); return; } // Ensure the LuaEnvironment is initialized before trying to execute code luaEnvironment.InitEnvironment(); // Cache a descriptive name to use in Lua error messages friendlyName = GetPath(transform) + ".LuaScript"; string s = GetLuaString(); luaFunction = luaEnvironment.LoadLuaFunction(s, friendlyName); initialised = true; }
/// <summary> /// Initialises the Lua environment and compiles the Lua string for execution later on. /// </summary> protected virtual void InitExecuteLua() { if (initialised) { return; } // Cache a descriptive name to use in Lua error messages friendlyName = gameObject.name + "." + ParentBlock.BlockName + "." + this.GetType().ToString() + " #" + CommandIndex.ToString(); Flowchart flowchart = GetFlowchart(); // See if a Lua Environment has been assigned to this Flowchart if (luaEnvironment == null) { luaEnvironment = flowchart.LuaEnv; } // No Lua Environment specified so just use any available or create one. if (luaEnvironment == null) { luaEnvironment = LuaEnvironment.GetLua(); } string s = GetLuaString(); luaFunction = luaEnvironment.LoadLuaFunction(s, friendlyName); // Add a binding to the parent flowchart if (flowchart.LuaBindingName != "") { Table globals = luaEnvironment.Interpreter.Globals; if (globals != null) { globals[flowchart.LuaBindingName] = flowchart; } } // Always initialise when playing in the editor. // Allows the user to edit the Lua script while the game is playing. if (!(Application.isPlaying && Application.isEditor)) { initialised = true; } }