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()");
 }
Esempio n. 2
0
        /// <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);
            }
        }
Esempio n. 3
0
        /// <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;
 }
Esempio n. 5
0
 public void AddCommand(string command, string help, LuaInterface.LuaFunction function, Room room)
 {
     room.AddCommand (command, help, function);
 }
Esempio n. 6
0
 public void AddCommand(string command, string help, LuaInterface.LuaFunction function)
 {
     BindMessageFunction (function, command);
     TextAdventure.Language.Processor.AddCommand (command, help, function);
 }
Esempio n. 7
0
 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);
     }
 }
Esempio n. 8
0
        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;
        }
Esempio n. 9
0
 public static object[] Table2Array(LuaInterface.LuaTable table)
 {
     return Table2List(table).ToArray();
 }
Esempio n. 10
0
 protected static void LuaEngine_HookException(object sender, LuaInterface.HookExceptionEventArgs e)
 {
     Console.WriteLine("EXCEPTION: " + e.Exception.ToString());
 }
Esempio n. 11
0
 protected static void LuaEngine_DebugHook(object sender, LuaInterface.DebugHookEventArgs e)
 {
     Console.WriteLine("DEBUG: " + e.LuaDebug.ToString());
 }
Esempio n. 12
0
 /// <summary>
 /// Creates a new instance of <c>LuaFunctions</c>
 /// </summary>
 /// <param name="vm">Lua VM</param>
 public LuaFunctions(ref LuaInterface.Lua vm)
 {
     _lua = vm;
 }
Esempio n. 13
0
 void lua_HookException(object sender, LuaInterface.HookExceptionEventArgs e)
 {
     System.Diagnostics.Debug.WriteLine(e.Exception.Message);
 }
Esempio n. 14
0
        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);
                }
            }
        }