public int CallLuaFunction(Character chara, string functionName, params object[] args) { DynValue res = new DynValue(); return(lua.LuaEngine.CallLuaStatusEffectFunction(chara, this, functionName, args)); if (!script.Globals.Get(functionName).IsNil()) { res = script.Call(script.Globals.Get(functionName), args); if (res != null) { return((int)res.Number); } } }
/// <summary> /// Luaスクリプト関数実行. /// </summary> public void CallFunction(DynValue function, params object[] args) { if (function.IsNotNil() && function.Type == DataType.Function) { try { LuaScript.Call(function, args); } catch (ScriptRuntimeException ex) { Debug.LogErrorFormat("Lua Call error:\n{0}", ex.DecoratedMessage); } } else { Debug.LogErrorFormat("Invalid lua function passed to LuaController.Call"); } }
/// <summary> /// Safely call a function on the active script /// </summary> /// <param name="function"></param> /// <param name="args"></param> public void Call(DynValue function, DynValue[] args = null) { if (EventsModule == null) { return; } try { lock (EventsModule.InvokeLock) { lock (LuaScript) { if (args != null) { LuaScript.Call(function, args); } else { LuaScript.Call(function); } } } } catch (ArgumentException e) { _logger.Error("[{0}-LUA]: Error: {1}", ProfileModel.Name, e.Message); } catch (InternalErrorException e) { _logger.Error("[{0}-LUA]: Error: {1}", ProfileModel.Name, e.DecoratedMessage); } catch (SyntaxErrorException e) { _logger.Error("[{0}-LUA]: Error: {1}", ProfileModel.Name, e.DecoratedMessage); } catch (ScriptRuntimeException e) { _logger.Error("[{0}-LUA]: Error: {1}", ProfileModel.Name, e.DecoratedMessage); } }
public void Update(float delta, float total) { m_script["HorizonHeight"] = HorizonHeight; m_script.Call("Update", delta, total); }
public override void Update(float delta, float total) { base.Update(delta, total); m_script.Call("Update", delta); }
// Methods public static void Load(string dataDir, string stageID, GameEntry game) { Data.Clear(); // Throw exceptions if necessary if (!Directory.Exists(dataDir)) { throw new DirectoryNotFoundException( $"Cannot load stage from \"{dataDir}\". Data Directory not found!"); } if (string.IsNullOrEmpty(stageID)) { throw new ArgumentNullException("stageID", "Cannot load stage. Invalid Stage ID!"); } GameType = game; ID = stageID; DataDir = dataDir; var resDir = new AssetDirectory(game.ResourcesDir); Data.ModelDirectories.Add(resDir); Data.ResourceDirectories.Add(resDir); // Make cache directory CacheDir = Path.Combine(Program.StartupPath, Program.CachePath, stageID); string editorCachePath = Path.Combine( CacheDir, EditorCache.FileName); Directory.CreateDirectory(CacheDir); // Load Editor Cache bool cacheExists = File.Exists(editorCachePath); EditorCache = new EditorCache() { GameType = game.Name, }; if (cacheExists) { var editorCache = new EditorCache(); editorCache.Load(editorCachePath); if (editorCache.GameType == game.Name) { EditorCache = editorCache; } } // Lua Script string pth = Path.Combine(Program.StartupPath, Program.ScriptsPath, LuaScript.GamesDir, $"{game.ShortName}{LuaScript.Extension}"); if (script == null || scriptPath != pth) { script = new LuaScript(); scriptPath = pth; try { script.DoScript(scriptPath); var canAddSetLayer = script.GetValue("CanAddSetLayer"); SceneView.CanAddLayer = (canAddSetLayer != null && canAddSetLayer.GetType() == typeof(bool)) ? (bool)canAddSetLayer : false; } catch (Exception ex) { LuaTerminal.LogError($"ERROR: {ex.Message}"); } } // Unpack/Load var unpackStopWatch = System.Diagnostics.Stopwatch.StartNew(); try { script.Call("Load", dataDir, CacheDir, stageID); } catch (Exception ex) { LuaTerminal.LogError($"ERROR: {ex.Message}, {ex.StackTrace}"); } unpackStopWatch.Stop(); Console.WriteLine("Done unpacking! Time: {0}(ms).", unpackStopWatch.ElapsedMilliseconds); // Generate new Editor Cache if (cacheExists) { File.Delete(editorCachePath); } EditorCache.Save(editorCachePath, true); // TODO: Remove this line //CurrentSetLayer = Sets[0]; }