public ScriptWrapper(/*bool overworld = false*/) { script = LuaScriptBinder.BoundScript(/*overworld*/); Bind("_getv", (Func <Script, string, DynValue>) this.GetVar); script.DoString(toDoString, null, scriptname); instances.Add(this); }
public ScriptWrapper(/*bool overworld = false*/) { script = LuaScriptBinder.BoundScript(/*overworld*/); this.Bind("_getv", (Func <Script, string, DynValue>) this.GetVar); string toDoString = "setmetatable({}, {__index=function(t, name) return _getv(name) end}) "; script.DoString(toDoString, null, scriptname); instances.Add(this); }
private void PrepareWave() { DynValue nextWaves = script.GetVar("nextwaves"); waves = new ScriptWrapper[nextWaves.Table.Length]; waveNames = new string[waves.Length]; int currentWaveScript = 0; try { List <int> indexes = new List <int>(); for (int i = 0; i < waves.Length; i++) { currentWaveScript = i; DynValue ArenaStatus = UserData.Create(ArenaManager.luaStatus); waves[i] = new ScriptWrapper() { script = LuaScriptBinder.BoundScript() }; waves[i].script.Globals.Set("Arena", ArenaStatus); waves[i].script.Globals["EndWave"] = (Action)EndWaveTimer; waves[i].script.Globals["State"] = (Action <Script, string>)UIController.SwitchStateOnString; waves[i].script.Globals["CreateProjectile"] = (Func <Script, string, float, float, string, DynValue>)CreateProjectile; waves[i].script.Globals["CreateProjectileAbs"] = (Func <Script, string, float, float, string, DynValue>)CreateProjectileAbs; if (nextWaves.Table.Get(i + 1).Type != DataType.String) { UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, "Non-string value encountered in nextwaves table"); return; } else { waveNames[i] = nextWaves.Table.Get(i + 1).String; } waves[i].script.Globals["wavename"] = nextWaves.Table.Get(i + 1).String; try { waves[i].DoString(ScriptRegistry.Get(ScriptRegistry.WAVE_PREFIX + nextWaves.Table.Get(i + 1).String)); indexes.Add(i); } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(nextWaves.Table.Get(i + 1).String + ".lua", ex.DecoratedMessage); } catch (Exception ex) { if (!GlobalControls.retroMode && !ScriptRegistry.dict.ContainsKey(ScriptRegistry.WAVE_PREFIX + nextWaves.Table.Get(i + 1).String)) { UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, "The wave " + nextWaves.Table.Get(i + 1).String + " doesn't exist."); } else { UnitaleUtil.DisplayLuaError("<UNKNOWN LOCATION>", ex.Message + "\n\n" + ex.StackTrace); } } } Table luaWaveTable = new Table(null); for (int i = 0; i < indexes.Count; i++) { luaWaveTable.Set(i + 1, UserData.Create(waves[indexes[i]])); } script.SetVar("Wave", DynValue.NewTable(luaWaveTable)); } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(nextWaves.Table.Get(currentWaveScript + 1).String + ".lua", ex.DecoratedMessage); } }