public Main(RemoteHooking.IContext InContext, String InChannelName) { Console.WriteLine("test"); luaInterface = RemoteHooking.IpcConnectClient<LuaInterface>(InChannelName); ChannelName = InChannelName; luaInterface.WriteLine("get current process id: " + RemoteHooking.GetCurrentProcessId()); luaInterface.WriteLine("end main()"); }
/// <summary> /// Handles Lua irc commands, especially interpreting. /// </summary> /// <param name="vm">Lua virtual machine</param> /// <param name="chan">Channel name.</param> /// <param name="msg">Message sent.</param> public static void HandleLuaCommands(LuaInterface.Lua vm, string chan, string msg) { var regex = new Regex(@"lua\s*\{\s*(?<lcode>.+)\s*\}"); if (!regex.IsMatch(msg)) return; var code = regex.Match(msg).Groups["lcode"].ToString(); try { vm.DoString(code); } catch(Exception x) { Log.ErrorException("Lua compile error.", x); } }
/// <summary> /// Registers Lua functions found in the specified target. /// </summary> /// <param name="luaFunctions">Global lua function table.</param> /// <param name="target">Object (class,struct) to search in.</param> /// <param name="vm">The Lua virtual machine.</param> public static void RegisterLuaFunctions(LuaInterface.Lua vm, ref Dictionary<string, LuaFunctionDescriptor> luaFunctions, object target) { if (vm == null || luaFunctions == null) return; var type = target.GetType(); foreach(var method in type.GetMethods()) { foreach(var attribute in Attribute.GetCustomAttributes(method)) { var luaFunctionAttribute = attribute as LuaFunctionAttribute; if (luaFunctionAttribute == null) continue; var attr = luaFunctionAttribute; var parameters = new List<string>(); var paramInfo = method.GetParameters(); if(attr.FunctionParameters != null && paramInfo.Length != attr.FunctionParameters.Length) { Console.Error.WriteLine("Function {0} (exported as {1}): argument number mismatch. Declared {2}, but requires {3}.", method.Name, attr.FunctionName, attr.FunctionParameters.Length, paramInfo.Length); break; } // build parameter doc hashtable. if (attr.FunctionParameters != null) parameters.AddRange(paramInfo.Select((t, i) => string.Format("{0} - {1}", t.Name, attr.FunctionParameters[i]))); var descriptor = new LuaFunctionDescriptor(attr.FunctionName, attr.FunctionDocumentation, parameters); luaFunctions.Add(attr.FunctionName, descriptor); vm.RegisterFunction(attr.FunctionName, target, method); } } }
public DebugHookEventArgs(LuaInterface.LuaDebug luaDebug) { this.luaDebug = luaDebug; }
public void AddCommand(string command, string help, LuaInterface.LuaFunction function, Room room) { room.AddCommand (command, help, function); }
public void AddCommand(string command, string help, LuaInterface.LuaFunction function) { BindMessageFunction (function, command); TextAdventure.Language.Processor.AddCommand (command, help, function); }
public void AddCommand(string name, string helpDesc, LuaInterface.LuaFunction perform) { Debug.LogWarning ("Adding command."); name = name.ToLower (); if (!commandHelp.ContainsKey (name)) { commandHelp.Add (name, helpDesc); luaCommands.Add (name, perform); } }
public static List<object> Table2List(LuaInterface.LuaTable table) { List<object> list = new List<object>(); foreach (DictionaryEntry e in table) { list.Add(e.Value); } return list; }
public static object[] Table2Array(LuaInterface.LuaTable table) { return Table2List(table).ToArray(); }
protected static void LuaEngine_HookException(object sender, LuaInterface.HookExceptionEventArgs e) { Console.WriteLine("EXCEPTION: " + e.Exception.ToString()); }
protected static void LuaEngine_DebugHook(object sender, LuaInterface.DebugHookEventArgs e) { Console.WriteLine("DEBUG: " + e.LuaDebug.ToString()); }
/// <summary> /// Creates a new instance of <c>LuaFunctions</c> /// </summary> /// <param name="vm">Lua VM</param> public LuaFunctions(ref LuaInterface.Lua vm) { _lua = vm; }
void lua_HookException(object sender, LuaInterface.HookExceptionEventArgs e) { System.Diagnostics.Debug.WriteLine(e.Exception.Message); }
void lua_DebugHook(object sender, LuaInterface.DebugHookEventArgs e) { if (e.LuaDebug.eventCode == LuaInterface.EventCodes.LUA_HOOKLINE) { for (bool isEntering = true; _isPausePending; isEntering = false) { if (isEntering) { ChangeState(AppState.Pause, e.LuaDebug.currentline); } System.Threading.Thread.Sleep(0); } } }