diff options
| author | Michael <[email protected]> | 2017-02-18 10:37:11 -0500 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-02-18 10:37:11 -0500 |
| commit | 9b8d5861a954610713ae66a53d2ac067991d9b68 (patch) | |
| tree | e550f758e52ec8ca12357d91c9fa13907e70c4f3 /ShiftOS_TheReturn/Scripting.cs | |
| parent | 30823a0778614d0f9fd6f82b5d9eb03aab41280d (diff) | |
| download | shiftos_thereturn-9b8d5861a954610713ae66a53d2ac067991d9b68.tar.gz shiftos_thereturn-9b8d5861a954610713ae66a53d2ac067991d9b68.tar.bz2 shiftos_thereturn-9b8d5861a954610713ae66a53d2ac067991d9b68.zip | |
WHOA LUA STUFF :dancer:
Diffstat (limited to 'ShiftOS_TheReturn/Scripting.cs')
| -rw-r--r-- | ShiftOS_TheReturn/Scripting.cs | 32 |
1 files changed, 32 insertions, 0 deletions
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<string, Action<object>>((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<string, dynamic>((objName) => { @@ -166,6 +183,21 @@ namespace ShiftOS.Engine.Scripting {e.Message}"); } } + + /// <summary> + /// Occurs when a Lua event is fired by C#. + /// </summary> + private static event Action<string, object> LuaEvent; + + /// <summary> + /// Raises a Lua event with the specified name and caller object. + /// </summary> + /// <param name="eventName">The name of the event. Scripts use this to check what type of event occurred.</param> + /// <param name="caller">The caller of the event. Scripts can use this to check if they should handle this event.</param> + public static void RaiseEvent(string eventName, object caller) + { + LuaEvent?.Invoke(eventName, caller); + } } [Exposed("net")] |
