コード例 #1
0
        public void Push(GLua GLua, Object obj)
        {
            if (obj is Delegate dele)
            {
                Int32 cfunc(IntPtr L)
                {
                    List <Object> args = new List <Object>();

                    foreach (ParameterInfo param in dele.Method.GetParameters())
                    {
                        args.Add(GLua.Get(param.ParameterType, param.Position + 1));
                    }
                    Object rtn = dele.DynamicInvoke(args.ToArray());

                    if (rtn != null)
                    {
                        GLua.Push(rtn, rtn.GetType());
                        return(1);
                    }
                    return(0);
                }

#pragma warning disable IDE0009 // Member access should be qualified. will post issue on forums
                GLua.PushCFunction(cfunc);
#pragma warning restore IDE0009
            }
            else
            {
                throw new Exception("wrapper func must be castable to delegate");
            }
        }
コード例 #2
0
 public void Push(GLua GLua, object obj)
 {
     if (obj is Delegate dele)
     {
         CFunc cfunc = (IntPtr L) => {
             List <object> args = new List <object>();
             foreach (var param in dele.Method.GetParameters())
             {
                 args.Add(GLua.Get(param.ParameterType, param.Position + 1));
             }
             var rtn = dele.DynamicInvoke(args.ToArray());
             if (rtn != null)
             {
                 GLua.Push(rtn, rtn.GetType());
                 return(1);
             }
             return(0);
         };
         GCHandle gch = GCHandle.Alloc(cfunc);
         GLua.AddLuaReference(gch);
         GLua.PushCFunction(cfunc);
     }
     else
     {
         throw new Exception("wrapper func must be castable to delegate");
     }
 }
コード例 #3
0
        public static int Open(ref lua_State state)
        {
            ClientConsole.RerouteConsole();
            ClientConsole.Color = new Color(0, 150, 255);
            Lua = GLua.Get(state);

            Lua.CreateTable();

            Lua.Push <Action <string> >(Dump);
            Lua.SetField(-2, "Dump");

            Lua.SetField(GLua.LUA_GLOBALSINDEX, "csluaview");

            var container = NativeInterface.Load <INetworkStringTableContainer>("engine", StringTableInterfaceName.CLIENT);
            var tablePtr  = container.FindTable("client_lua_files");
            var table     = JIT.ConvertInstance <INetworkStringTable>(tablePtr);

            Console.WriteLine($"dotnet table ptr: {tablePtr.ToString("X8")}");
            //var path0 = table.GetString(0); //hangs here

            //for (int i = 0; i < table.GetNumStrings(); i++)
            //{
            //}

            //var stringTable = StringTable.FindTable<int>("client_lua_files");
            //var luaFiles = stringTable.Select(s => new LuaFile { Path = s.String, CRC = s.UserData }).ToList();

            Console.WriteLine("DotNet Clientside Lua Viewer Loaded!");
            return(0);
        }
コード例 #4
0
 public static Int32 Open64([MarshalAs(UnmanagedType.I8)] Int64 Ptr)
 {
     try
     {
         return(Module.Open(GLua.Get(Marshal.PtrToStructure <Lua_State64>(new IntPtr(Ptr)))));
     }
     catch (Exception E)
     {
         WriteException(E);
         return(-1);
     }
 }
コード例 #5
0
 public static Int32 Close64([MarshalAs(UnmanagedType.I8)] Int64 Ptr)
 {
     try
     {
         GLua  Lua = GLua.Get(Marshal.PtrToStructure <Lua_State64>(new IntPtr(Ptr)));
         Int32 Ret = Module.Close(Lua);
         Lua.Close();
         return(Ret);
     }
     catch (Exception E)
     {
         WriteException(E);
         return(-1);
     }
 }
コード例 #6
0
ファイル: Module.cs プロジェクト: Ethan-the-axolotl/gm_dotnet
        public static int Open(ref lua_State state)
        {
            GLua = GLua.Get(state);

            GLua.CreateTable();

            GLua.Push("woop was here");
            GLua.SetField(-2, "var");

            GLua.Push <Func <string, int, string> >(DoAThing);
            GLua.SetField(-2, "wrapped");

            GLua.SetField(GLua.LUA_GLOBALSINDEX, "dotnet");

            Console.WriteLine("DotNet loaded");
            return(0);
        }
コード例 #7
0
        public static int Open(ref lua_State state)
        {
            GLua = GLua.Get(state);

            GLua.CreateTable();

            GLua.Push(new Func <string, object>((string str) => {
                GLua.Push <string>("hello there");
                GLua.Call(1, 2);
                Console.WriteLine(GLua.Get <string>(5));
                GLua.Pop();
                GLua.Push <string>("hello there");
                GLua.Call(1, 2);
                Console.WriteLine(GLua.Get <string>(5));
                return(0);
            }));
            GLua.SetField(-2, "test");

            GLua.Push(new Func <string, string, int, object>((string path, string name, int boundObjectAmout) => {
                int res = instances.Count;
                try {
                    instances.Add(NodeInstance.InstantiateSync(path, name, boundObjectAmout));
                    return(res);
                }
                catch (Exception e) {
                    return(e.ToString());
                }
            }));
            GLua.SetField(-2, "instantiateSync");

            GLua.Push(new Func <string, string, int, object>((string path, string name, int boundObjectAmout) => {
                int res = instances.Count;
                NodeInstance.InstantiateAsync(path, name, boundObjectAmout).ContinueWith(taskResult => {
                    if (taskResult.IsFaulted)
                    {
                        newInstancesExceptionsAsync.Add(res, string.Join(",", taskResult.Exception.InnerExceptions.Select(x => x.ToString()).ToArray()));
                    }
                    else
                    {
                        newInstancesAsync.Add(res, taskResult.Result);
                    }
                });
                return(res);
            }));
            GLua.SetField(-2, "instantiateAsync");

            GLua.Push(new Func <int, bool>((int ptr) => {
                if (newInstancesAsync.ContainsKey(ptr))
                {
                    newInstancesAsync.Remove(ptr);
                    return(true);
                }
                return(false);
            }));
            GLua.SetField(-2, "checkForNewAsyncInstances");

            GLua.Push(new Func <int, object>((int ptr) => {
                if (newInstancesExceptionsAsync.ContainsKey(ptr))
                {
                    string str = newInstancesExceptionsAsync[ptr];
                    newInstancesExceptionsAsync.Remove(ptr);
                    return(str);
                }
                return(false);
            }));
            GLua.SetField(-2, "checkForNewAsyncInstancesExceptions");

            GLua.Push(new Func <int, string>((int instance) => {
                return(JsonConvert.SerializeObject(instances[instance].Methods));
            }));
            GLua.SetField(-2, "getInstanceMethods");

            GLua.Push(new Func <int, string, string, string>((int instance, string funcName, string args) => {
                Func <object> getHandler = new Func <object>(() => {
                    GLua.Push <string>("hello there");
                    GLua.Call(1, 2);
                    Console.WriteLine(GLua.Get <string>(5));
                    GLua.Pop();
                    return(0);
                });
                try {
                    object result = instances[instance].Call(funcName, JsonConvert.DeserializeObject <object[]>(args));
                    if (result == null)
                    {
                        return(null);
                    }

                    return(JsonConvert.SerializeObject(result));
                }
                catch (Exception e) {
                    Console.WriteLine(e);
                    return("Error: " + e.Message);
                }
            }));
            GLua.SetField(-2, "callInstanceMethod");

            GLua.Push(new Func <int, object>((int instance) => {
                instances[instance] = null;
                return(null);
            }));
            GLua.SetField(-2, "removeInstance");

            GLua.Push(new Func <int, object>((int instance) => {
                instances[instance] = null;
                return(null);
            }));
            GLua.SetField(-2, "getInstanceObject");

            GLua.Push(new Func <int, object>((int instance) => {
                instances[instance] = null;
                return(null);
            }));
            GLua.SetField(-2, "removeInstance");

            GLua.Push(new Func <double>(() => {
                return(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds);
            }));
            GLua.SetField(-2, "getUnixTime");

            GLua.SetField(GLua.LUA_GLOBALSINDEX, WRAPPER_OBJECT_NAME);
            return(0);
        }