From 9b8d5861a954610713ae66a53d2ac067991d9b68 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 18 Feb 2017 10:37:11 -0500 Subject: WHOA LUA STUFF :dancer: --- ShiftOS_TheReturn/Scripting.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'ShiftOS_TheReturn/Scripting.cs') diff --git a/ShiftOS_TheReturn/Scripting.cs b/ShiftOS_TheReturn/Scripting.cs index e699939..c934fc6 100644 --- a/ShiftOS_TheReturn/Scripting.cs +++ b/ShiftOS_TheReturn/Scripting.cs @@ -45,6 +45,15 @@ namespace ShiftOS.Engine.Scripting public LuaInterpreter() { + Lua(@"function totable(clrlist) + local t = {} + local it = clrlist:GetEnumerator() + while it:MoveNext() do + t[#t+1] = it.Current + end + return t +end"); + SetupAPIs(); Application.ApplicationExit += (o, a) => { @@ -55,6 +64,14 @@ namespace ShiftOS.Engine.Scripting public void SetupAPIs() { + Lua.registerEvent = new Action>((eventName, callback) => + { + LuaEvent += (e, s) => + { + if(e == eventName) + callback?.Invoke(s); + }; + }); //This temporary proxy() method will be used by the API prober. Lua.proxy = new Func((objName) => { @@ -166,6 +183,21 @@ namespace ShiftOS.Engine.Scripting {e.Message}"); } } + + /// + /// Occurs when a Lua event is fired by C#. + /// + private static event Action LuaEvent; + + /// + /// Raises a Lua event with the specified name and caller object. + /// + /// The name of the event. Scripts use this to check what type of event occurred. + /// The caller of the event. Scripts can use this to check if they should handle this event. + public static void RaiseEvent(string eventName, object caller) + { + LuaEvent?.Invoke(eventName, caller); + } } [Exposed("net")] -- cgit v1.2.3