private static void InitEditorState(Lua state) { state.LoadCLRPackage(); string resName = "WorldSmith.Scripts.WorldsmithImports.lua"; Assembly asm = Assembly.GetExecutingAssembly(); using (System.IO.Stream s = asm.GetManifestResourceStream(resName)) using (System.IO.StreamReader reader = new System.IO.StreamReader(s)) { string data = reader.ReadToEnd(); state.DoString(data, resName); } state["Units"] = DotaData.AllUnits; state["Heroes"] = DotaData.AllHeroes; state["Abilities"] = DotaData.AllAbilities; state["Items"] = DotaData.DefaultItems; state["Events"] = DotaData.Events; //Bind the DataClass enum state.DoString("DataClass = {}"); state["DataClass.Default"] = DotaDataObject.DataObjectInfo.ObjectDataClass.Default; state["DataClass.Override"] = DotaDataObject.DataObjectInfo.ObjectDataClass.Override; state["DataClass.Custom"] = DotaDataObject.DataObjectInfo.ObjectDataClass.Custom; }
void Start() { lua = new NLua.Lua(); lua.LoadCLRPackage(); var method = typeof(Debug).GetMethod("Log", new Type[] { typeof(object) }); lua.RegisterFunction("print", method); }
public bool Awakening() { spaar.ModLoader.Game.OnSimulationToggle += GameOnOnSimulationToggle; spaar.ModLoader.Game.OnLevelWon += GameOnOnLevelWon; env = new NLua.Lua(); env.LoadCLRPackage(); env["this"] = this; // Give the script access to the gameobject. env["transform"] = transform; env["gameObject"] = gameObject; env["enabled"] = enabled; env["useAPI"] = new Action(UseAPI); env["disableAPI"] = new Action(DisableAPI); if (Settings.useAPI) { Besiege.SetUp(); env["besiege"] = Besiege._besiege; } try { env.DoString(source); } catch (NLua.Exceptions.LuaException e) { Debug.LogError(FormatException(e), context: gameObject); return(false); } Call("Awake"); return(true); }
public void Init() { if (IsInitialized) throw new InvalidOperationException("Already Initialized!"); if (_state != null) _state.Dispose(); _state = new Lua(); _state.LoadCLRPackage(); _state.DoString(@"luanet.load_assembly('WGestures.Core'); luanet.load_assembly('WindowsInput'); luanet.load_assembly('WGestures.Common'); GestureModifier=luanet.import_type('WGestures.Core.GestureModifier'); VK=luanet.import_type('WindowsInput.Native.VirtualKeyCode'); Native=luanet.import_type('WGestures.Common.OsSpecific.Windows.Native'); ", "_init"); _state["Input"] = Sim.Simulator; _state.RegisterFunction("ReportStatus", this, typeof(ScriptCommand).GetMethod("OnReportStatus")); if(InitScript != null) { DoString(InitScript, "Init"); } IsInitialized = true; }
public bool Awakening() { spaar.ModLoader.Game.OnSimulationToggle += GameOnOnSimulationToggle; spaar.ModLoader.Game.OnLevelWon += GameOnOnLevelWon; env = new NLua.Lua(); env.LoadCLRPackage(); env["this"] = this; // Give the script access to the gameobject. env["transform"] = transform; env["gameObject"] = gameObject; env["enabled"] = enabled; env["useAPI"] = new Action(UseAPI); env["disableAPI"] = new Action(DisableAPI); if (Settings.useAPI) { Besiege.SetUp(); env["besiege"] = Besiege._besiege; } try { env.DoString(source); } catch (NLua.Exceptions.LuaException e) { Debug.LogError(FormatException(e), context: gameObject); return false; } Call("Awake"); return true; }
public void TestBinaryLoadFile () { using (Lua lua = new Lua ()) { lua.LoadCLRPackage (); if (IntPtr.Size == 4) lua.DoFile ("test_32.luac"); else lua.DoFile ("test_64.luac"); int width = (int)(double)lua ["width"]; int height = (int)(double)lua ["height"]; string message = (string)lua ["message"]; int color_g = (int)(double)lua ["color.g"]; LuaFunction func = (LuaFunction)lua ["func"]; object[] res = func.Call (12, 34); int x = (int)(double)res [0]; int y = (int)(double)res [1]; //function func(x,y) // return x,x+y //end Assert.AreEqual (100, width); Assert.AreEqual (200, height); Assert.AreEqual ("Hello World!", message); Assert.AreEqual (20, color_g); Assert.AreEqual (12, x); Assert.AreEqual (46, y); } }
public ScriptComponent() { Family = ComponentFamily.Script; lua = new Lua(); lua.LoadCLRPackage(); }
void Start() { LuaState = new Lua(); LuaState.LoadUnityExpand(); LuaState.LoadImportExpand(); LuaState.LoadCLRPackage("Using"); LuaState.CallLunaFunction("lunatest.lua", "Start", this.gameObject); LuaState.CheckStack(); }
static void Main (string [] args) { using (var l = new Lua ()) { l.LoadCLRPackage (); l.DoString (" import ('ConsoleTest') "); l.DoString (@" Program.Method (1) "); } }
void Start() { LuaState = new Lua(); LuaState.LoadCLRPackage(); LuaState.LoadUnityExpand(); var ret = LuaState.DoString(@"return require 'requiretest'"); TestLib = ret[0] as LuaTable; var startCallback = TestLib["Start"] as LuaFunction; startCallback.Call(this.gameObject); }
void Awake() { env = new Lua(); env.LoadCLRPackage(); env["this"] = this; // Give the script access to the gameobject. env["transform"] = transform; env["cube"] = cube; env["btnObj"] = btnObj; env["Sphere"] = Sphere; StartCoroutine(loadLua()); }
static void Main (string [] args) { using (var l = new Lua ()) { l.LoadCLRPackage (); l.DoString (" import ('ConsoleTest', 'NLuaTest.Mock') "); l.DoString (@" e1 = Entity() e2 = Entity ('Another world') e3 = Entity (10) "); } }
public void TestCLRPackage () { using (Lua lua = new Lua ()) { lua.LoadCLRPackage (); lua.DoString ("import ('NLuaTest', 'NLuaTest.Mock') "); lua.DoString ("test = TestClass()"); lua.DoString ("test:setVal(3)"); object[] res = lua.DoString ("return test"); TestClass test = (TestClass)res [0]; Assert.AreEqual (3, test.testval); } }
// this LoadCLRPackage can rename the 'import' function public static void LoadCLRPackage(this Lua lua, string newImportName) { lua.LoadCLRPackage(); if (!string.IsNullOrEmpty(newImportName)) { string str = string.Format(@" if _G.import then -- To avoid ambiguity, rename _G.import _G.{0} = _G.import; _G.import = nil; end", newImportName); LuaLib.LuaLDoString(lua.LuaState, str); } }
public void TestUseNSUrl () { using (Lua lua = new Lua ()) { lua.LoadCLRPackage (); lua.DoString ("import ('monotouch', 'MonoTouch.Foundation') "); lua.DoString ("testURL = NSUrl('http://nlua.org/?query=param')"); lua.DoString ("host = testURL.Host"); object res = lua["host"]; string host = (string)res; Assert.AreEqual ("nlua.org", host); } }
public static void runLua(String code) { try { Lua vm = new Lua(); vm.InstallRunGNatives(); if (Static.isCLR) vm.LoadCLRPackage(); vm.DoString(code); } catch (Exception e) { log.error("Erro: " + RunGEngine.decipherCatch(e)); Static.fine = false; } }
/// <summary> /// Try to execute a Lua command given in a string /// </summary> /// <param name="luaCommand"></param> public static bool executeCommand(string luaCommand) { Lua lua = new Lua(); lua.LoadCLRPackage(); lua.DoString(@" import ('TextRPG', 'TextRPG') import ('System') "); try { lua.DoString(luaCommand); return true; } catch (Exception e) { return false; } }
void Awake() { env = new Lua(); env.LoadCLRPackage(); env["this"] = this; // Give the script access to the gameobject. env["transform"] = transform; //System.Object[] result = new System.Object[0]; try { //result = env.DoString(source); env.DoString(source); } catch(NLua.Exceptions.LuaException e) { Debug.LogError(FormatException(e), gameObject); } }
public static void Main(string[] args) { try { using (Lua lua = new Lua()) { //lua.OpenLibs(); // steffenj: Lua 5.1.1 API change (all libs already opened in Lua constructor!) lua.NewTable("arg"); LuaTable argc = (LuaTable)lua ["arg"]; argc [0] = "NLua"; for (int i = 0; i < args.Length; i++) { argc [i + 1] = args [i]; } argc ["n"] = args.Length; lua.LoadCLRPackage(); try { lua.DoString(lua_script, "lua"); } catch (Exception e) { // limit size of stack traceback message to roughly 1 console screen height string trace = e.StackTrace; if (e.StackTrace.Length > 1300) { trace = e.StackTrace.Substring(0, 1300) + " [...] (traceback cut short)"; } Console.WriteLine(); Console.WriteLine(e.Message); Console.WriteLine(e.Source + " raised a " + e.GetType().ToString()); Console.WriteLine(trace); // wait for key press if there is an error Console.ReadKey(); } } } catch (Exception e) { Console.WriteLine(); Console.WriteLine(e.Message); Console.WriteLine(e.Source + " raised a " + e.GetType().ToString()); Console.ReadKey(); } }
/* const string source = @"luanet.load_assembly('mscorlib') luanet.load_assembly('test') Class1 = luanet.import_type('test.Class1') cc = Class1() cc:Log('fffffffffffffffffffffffff') print('gggggggggggggggggggg---luaaaaaaaaaaaaaaaa') "; Debug.WriteLine("start app========================>>>>>>>>>>>"); using (Lua lua = new Lua()) { lua.LoadCLRPackage(); Type[] types = new Type[] { typeof(String) }; lua.RegisterFunction("print", null, typeof(Debug).GetMethod("WriteLine", types)); lua.DoString(source); } * */ // Use this for initialization IEnumerator Start () { yield return new WaitForSeconds(3); env = new Lua(); env.LoadCLRPackage(); env["this"] = this; // Give the script access to the gameobject. env["transform"] = transform; //System.Object[] result = new System.Object[0]; try { //result = env.DoString(source); env.DoString(source); } catch (NLua.Exceptions.LuaException e) { Debug.LogError(FormatException(e), gameObject); } Call("Start"); }
public static void Init() { if (!isInited) { environment = new Lua(); environment.LoadCLRPackage(); try { environment.DoString(initialScriptCode); isInited = true; } catch(NLua.Exceptions.LuaException e) { Debug.Log("[ScriptManager-Init-Ex] " + e.ToString()); } } }
/// <summary> /// Execute a script from file by name /// </summary> /// <param name="scriptName"></param> public static bool executeScript(string scriptName) { Lua lua = new Lua(); lua.LoadCLRPackage(); lua.DoString(@" import ('TextRPG', 'TextRPG') import ('System') "); try { var x = lua.DoFile(scriptName+".lua"); GUI.Instance.appendToOutput(x.ToString()); return true; } catch (Exception e) { return false; } }
static void Main(string [] args) { using (Lua lua = new Lua ()) { lua.LoadCLRPackage (); lua.DoString (@" import ('ConsoleTest') v = Vector() v.x = 10 v.y = 3 v = v*2 "); var v = (ConsoleTest.Vector)lua ["v"]; lua.DoString (@" x = 2*v"); var x = (Vector)lua ["x"]; } }
public static Lua GetLua() { Lua lua = new Lua(); lua.LoadCLRPackage(); lua.DoString(@" import ('Systen') "); lua.DoString(@" import ('Systen.IO') "); lua.DoString(@" import ('Systen.Text') "); lua.DoString(@" import ('Systen.Text.RegularExpressions') "); lua.DoString(" import ('" + typeof(Seven).Assembly.GetName().Name + "') "); lua.DoString(Resource.GetTextFromResource("lua.scripts", typeof(Seven).Assembly)); lua.DoString("Element = luanet.import_type(\"Atmosphere.Reverence.Seven.Asset.Element\")"); lua.DoString("Status = luanet.import_type(\"Atmosphere.Reverence.Seven.Asset.Status\")"); lua.DoString("Party = luanet.import_type(\"Atmosphere.Reverence.Seven.Party\")"); return lua; }
/// <summary> /// A label for displaying values obtained through Lua scripts. /// </summary> /// <param name="filePath">The path to the Lua script. The script must contain a GetValue() function, which returns the desired text to be displayed.</param> /// <param name="lua">Obtained by calling GetLua() on a WatchManager32Bit.</param> public LuaWatch(string filePath, Lua.Lua lua) { NLua.Lua n = new NLua.Lua(); n.LoadCLRPackage(); n.DoString("import ('DeSmuME_Watch', 'DeSmuME_Watch.Lua')"); n.DoFile(filePath); luaGetValue = n.GetFunction("GetValue"); this.lua = lua; n["WATCH"] = lua; if (luaGetValue == null) { throw new Exception("Lua script could not be loaded. Make sure it contains the function GetValue()."); } this.AutoSize = true; this.SetText("?"); }
static void Main(string [] args) { using (Lua lua = new Lua()) { lua.LoadCLRPackage (); lua.DoString (@" import ('ConsoleTest') v = Vector() v.x = 10 v.y = 3 v = v*2 v = 3 * v "); var v = lua ["v"]; // lua.LoadCLRPackage (); } }
public override IEnumerable<Kbtter4Plugin> Load(Kbtter instance, IList<string> filenames) { var list = new List<Kbtter4LuaPlugin>(); var files = filenames.Where(p => p.EndsWith(".lua")); foreach (var i in files) { try { Lua l = new Lua(); l.LoadCLRPackage(); l["Kbtter4"] = new Kbtter4PluginProvider(instance); l.DoFile(i); list.Add(new Kbtter4LuaPlugin(l,instance)); } catch (Exception e) { instance.LogError("Luaプラグイン読み込み中にエラーが発生しました : " + e.Message); } } return list; }
public override int Load(IList<string> filenames) { var err = 0; var list = filenames.Where(p => p.EndsWith(".lua")); foreach (var i in list) { var l = new Lua(); l.LoadCLRPackage(); l["Kbtter3"] = ep; try { luas.Add(l); l.DoFile(i); } catch (Exception e) { kbtter.LogError(string.Format("Luaプラグインローダー\n{0}の読み込み中にエラーが発生しました \n{1}", i, e.Message)); err++; } } return err; }
/// <summary> /// Run the specified script. /// </summary> /// <param name="scriptFile">Script file name</param> public void RunScript(string scriptFile) { if (File.Exists(scriptFile)) { try { using (NLua.Lua lua = new NLua.Lua()) { lua.LoadCLRPackage(); _luaAPI.RegisterFunctions(lua); lua.DoFile(scriptFile); LuaFunction fnc = lua.GetFunction("on_Run"); if (fnc != null) { fnc.Call(); } } } catch (LuaScriptException e) { MessageBox.Show(e.Message, Resources.ScriptException, MessageBoxButtons.OK); } } }
public void TestOverloadedMethodCallOnBase () { using (var l = new Lua ()) { l.LoadCLRPackage (); l.DoString (" import ('NLuaTest') "); l.DoString (@" p=parameter() r1 = testClass.read(p) -- is not working. it is also not working if the method in base class has two parameters instead of one r2 = testClass.read(1) -- is working "); string r1 = (string) l ["r1"]; string r2 = (string) l ["r2"]; Assert.AreEqual ("parameter-field1", r1, "#1"); Assert.AreEqual ("int-test" , r2, "#2"); } }
public void TestCallImplicitBaseMethod () { using (var l = new Lua ()) { l.LoadCLRPackage (); l.DoString ("import ('NLuaTest')"); l.DoString ("res = testClass.read() "); string res = (string)l ["res"]; Assert.AreEqual (testClass.read (), res); } }
public void TestGetStack () { using (Lua lua = new Lua ()) { lua.LoadCLRPackage (); m_lua = lua; lua.DoString (@" import ('NLuaTest') function f1 () f2 () end function f2() f3() end function f3() LuaTests.func() end f1 () "); } m_lua = null; }
public void TestExtensionMethods () { using (Lua lua = new Lua ()) { lua.LoadCLRPackage (); lua.DoString (@" import ('NLuaTest') v = Vector() v.x = 10 v.y = 3 v = v*2 "); var v = (Vector)lua ["v"]; double len = v.Lenght (); lua.DoString (" v:Lenght() "); lua.DoString (@" len2 = v:Lenght()"); double len2 = (double)lua ["len2"]; Assert.AreEqual (len, len2, "#1"); } }
public void TestStaticOperators () { using (Lua lua = new Lua ()) { lua.LoadCLRPackage (); lua.DoString (@" import ('NLuaTest') v = Vector() v.x = 10 v.y = 3 v = v*2 "); var v = (Vector)lua ["v"]; Assert.AreEqual (20, v.x, "#1"); Assert.AreEqual (6, v.y, "#2"); lua.DoString (@" x = 2 * v"); var x = (Vector)lua ["x"]; Assert.AreEqual (40, x.x, "#3"); Assert.AreEqual (12, x.y, "#4"); } }
public void TestCaseFields () { using (Lua lua = new Lua ()) { lua.LoadCLRPackage (); lua.DoString (@" import ('NLuaTest') x = TestCaseName() name = x.name; name2 = x.Name; Name = x.Name; Name2 = x.name"); Assert.AreEqual ("name", lua ["name"]); Assert.AreEqual ("**name**", lua ["name2"]); Assert.AreEqual ("**name**", lua ["Name"]); Assert.AreEqual ("name", lua ["Name2"]); } }
public Service() { this.LastAlert = new DateTime(1970, 01, 01, 0, 0, 0); this.LastENumber = ""; try { FeuerwehrCloud.Helper.Logger.WriteLine("| *** Initializing NLua..."); lua = new NLua.Lua(); lua.LoadCLRPackage(); lua ["Service"] = this; } catch (Exception ex) { if (ex.GetType().ToString() == "System.DllNotFoundException" && System.Environment.OSVersion.Platform == PlatformID.Win32NT) { // } else { // } FeuerwehrCloud.Helper.Logger.WriteLine(ex.ToString()); return; } System.IO.File.Delete("versions.txt"); System.IO.File.AppendAllText("versions.txt", System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().GetName().CodeBase) + ":" + Assembly.GetExecutingAssembly().GetName().Version.Major.ToString() + "." + Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString() + "." + Assembly.GetExecutingAssembly().GetName().Version.Build.ToString() + "." + Assembly.GetExecutingAssembly().GetName().Version.Revision.ToString() + "\r\n"); var plugins = System.IO.Directory.EnumerateFiles("./plugins", "FeuerwehrCloud.*.*.dll"); //FeuerwehrCloud.Plugin.IPlugin c = new FeuerwehrCloud.Input.SMTP.SMTPSever (); foreach (string currentFile in plugins) { try { if (!System.IO.File.Exists(currentFile + ".disabled")) { var DLL = Assembly.LoadFile(currentFile); var dllVer = DLL.GetName().Version; System.IO.File.AppendAllText("versions.txt", System.IO.Path.GetFileNameWithoutExtension(currentFile) + ":" + dllVer.Major.ToString() + "." + dllVer.Minor.ToString() + "." + dllVer.Build.ToString() + "." + dllVer.Revision.ToString() + "\r\n"); foreach (Type type in DLL.GetExportedTypes()) { FeuerwehrCloud.Plugin.IPlugin c; try { c = (FeuerwehrCloud.Plugin.IPlugin)Activator.CreateInstance(type); lua[System.IO.Path.GetFileNameWithoutExtension(currentFile).Replace(".", "_")] = c; //lua[System.IO.Path.GetFileNameWithoutExtension (currentFile)] = c; lua.DebugHook += HandleDebugHook; lua.RegisterFunction(System.IO.Path.GetFileNameWithoutExtension(currentFile).Replace(".", "_") + "_Execute", c, c.GetType().GetMethod("Execute")); if (c.Initialize(this)) { //FeuerwehrCloud.Helper.Logger.WriteLine(">>>>"+System.IO.Path.GetFileNameWithoutExtension (currentFile)); PlugIns.Add(System.IO.Path.GetFileNameWithoutExtension(currentFile), c); c.Event += delegate(object sender, object[] list) { /*Xamarin.Insights.Track ("Event", new System.Collections.Generic.Dictionary<string, string> { * {"ModuleName", c.Name }, * {"ServiceType", c.ServiceType.ToString()}, * {"NextAction", sender.ToString() + ".lua" } * });*/ lua["response"] = list; switch (c.ServiceType) { case FeuerwehrCloud.Plugin.ServiceType.input: if (list [0] == "pictures") { try { //FeuerwehrCloud.Helper.Logger.WriteLine("3||||"+Application.StartupPath +"/"+ sender.ToString () + ".lua"); lua.DoFile(Application.StartupPath + "/" + sender.ToString() + ".lua"); //FeuerwehrCloud.Helper.Logger.WriteLine("3||||"+Application.StartupPath +"/"+ sender.ToString () + ".lua"); } catch (Exception ex) { FeuerwehrCloud.Helper.Logger.WriteLine(FeuerwehrCloud.Helper.Helper.GetExceptionDescription(ex)); } } else if (list [0] == "text") { try { //FeuerwehrCloud.Helper.Logger.WriteLine("4||||"+Application.StartupPath +"/"+ sender.ToString () + ".lua"); lua.DoFile(Application.StartupPath + "/" + sender.ToString() + ".lua"); //FeuerwehrCloud.Helper.Logger.WriteLine("4||||"+Application.StartupPath +"/"+ sender.ToString () + ".lua"); } catch (Exception ex) { FeuerwehrCloud.Helper.Logger.WriteLine(FeuerwehrCloud.Helper.Helper.GetExceptionDescription(ex)); } } break; case FeuerwehrCloud.Plugin.ServiceType.processor: if (list [0] == "pictures") { try { //FeuerwehrCloud.Helper.Logger.WriteLine("1||||"+Application.StartupPath +"/"+ sender.ToString () + ".lua"); lua.DoFile(Application.StartupPath + "/" + sender.ToString() + ".lua"); //FeuerwehrCloud.Helper.Logger.WriteLine("1||||"+Application.StartupPath +"/"+ sender.ToString () + ".lua"); } catch (Exception ex) { FeuerwehrCloud.Helper.Logger.WriteLine(FeuerwehrCloud.Helper.Helper.GetExceptionDescription(ex)); } } else if (list [0] == "text") { try { //FeuerwehrCloud.Helper.Logger.WriteLine("5||||"+Application.StartupPath +"/"+ sender.ToString () + ".lua"); lua.DoFile(Application.StartupPath + "/" + sender.ToString() + ".lua"); //FeuerwehrCloud.Helper.Logger.WriteLine("5||||"+Application.StartupPath +"/"+ sender.ToString () + ".lua"); } catch (Exception ex) { FeuerwehrCloud.Helper.Logger.WriteLine(FeuerwehrCloud.Helper.Helper.GetExceptionDescription(ex)); try { } catch (Exception ex2) { var smtpClient = new System.Net.Mail.SmtpClient(); smtpClient.Host = "feuerwehrcloud.de"; smtpClient.Port = 25; smtpClient.EnableSsl = false; smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; var smtp = smtpClient; var mailMessage = new System.Net.Mail.MailMessage("*****@*****.**", "*****@*****.**"); mailMessage.Subject = "[FeuerwehrCloud] EXCEPTION AT " + System.Environment.MachineName; mailMessage.Body = FeuerwehrCloud.Helper.Helper.GetExceptionDescription(ex); using (var message = mailMessage) smtp.Send(message); } } } break; case FeuerwehrCloud.Plugin.ServiceType.output: try { //FeuerwehrCloud.Helper.Logger.WriteLine("2||||"+Application.StartupPath +"/"+ sender.ToString () + ".lua"); lua.DoFile(sender.ToString() + ".lua"); //FeuerwehrCloud.Helper.Logger.WriteLine("2||||"+Application.StartupPath +"/"+ sender.ToString () + ".lua"); } catch (Exception ex) { FeuerwehrCloud.Helper.Logger.WriteLine(FeuerwehrCloud.Helper.Helper.GetExceptionDescription(ex)); } break; } //FeuerwehrCloud.Helper.Logger.WriteLine(list[0].ToString()); }; } } catch (Exception ex) { FeuerwehrCloud.Helper.Logger.WriteLine(FeuerwehrCloud.Helper.Helper.GetExceptionDescription(ex)); } } } } catch (Exception ex) { FeuerwehrCloud.Helper.Logger.WriteLine("************ ERRROR ***************"); FeuerwehrCloud.Helper.Logger.WriteLine(FeuerwehrCloud.Helper.Helper.GetExceptionDescription(ex)); } } FeuerwehrCloud.Helper.Logger.WriteLine("| Loaded plugins: " + PlugIns.Count.ToString()); lua ["PlugIns"] = PlugIns; lua.DoFile("init_complete.lua"); FeuerwehrCloud.Helper.Logger.WriteLine("| Initialisation complete. System started."); FeuerwehrCloud.Helper.Logger.WriteLine("`·--- Startup complete. ----------------------- ----- -- -"); }
/// <summary> /// Load a single script from the specified manifest. /// </summary> private void LoadSingleScript(string path, ScriptManifest manifest) { string scriptFile = Path.Combine(path, manifest.ScriptFile); NLua.Lua lua = new NLua.Lua(); lua.LoadCLRPackage(); _luaAPI.RegisterFunctions(lua); bool success = true; try { lua.DoFile(scriptFile); LuaFunction fnc = lua.GetFunction("on_load"); if (fnc != null) { object[] res = fnc.Call(); if (res != null && res.Length == 1) { success = Convert.ToBoolean(res[0]); } } // Cache this script object for event callbacks if the // init function returns success. if (success) { if (_scriptObjects.ContainsKey(scriptFile)) { // BUGBUG: What if we have scripts that register events? We need to tell // them to unregister first. Add an interface for this. NLua.Lua oldScript = _scriptObjects[scriptFile]; oldScript.Dispose(); _scriptObjects.Remove(scriptFile); } _scriptObjects.Add(scriptFile, lua); } if (manifest.InstallToToolbar) { ToolbarDataItem item = new ToolbarDataItem { type = "button", name = "Script", label = manifest.Name, tooltip = manifest.Description, data = scriptFile, image = manifest.IconFile }; CRToolbarItemCollection.DefaultCollection.Add(item); } } catch (Exception e) { LogFile.WriteLine("Error loading script {0} : {1}", scriptFile, e.Message); success = false; } if (success) { LogFile.WriteLine("Loaded and initialised script {0}", scriptFile); } else { lua.Dispose(); } }