예제 #1
0
        internal GlobalContext(ILua lua)
        {
            this.lua = lua;

            lua.GetField(-10002, "SERVER");
            isServerSide = lua.GetBool(-1);

            module_contexts = new Dictionary <string, Tuple <GmodNetModuleAssemblyLoadContext, List <GCHandle> > >();

            int managed_func_type_id = lua.CreateMetaTable("ManagedFunction");

            unsafe
            {
                lua.PushCFunction(&ManagedFunctionMetaMethods.ManagedDelegateGC);
            }
            lua.SetField(-2, "__gc");
            lua.Pop(1);

            lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
            lua.PushNumber(managed_func_type_id);
            lua.SetField(-2, ManagedFunctionMetaMethods.ManagedFunctionIdField);
            lua.Pop(1);

            lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
            lua.CreateTable();

            lua.PushManagedFunction(LoadModule);
            lua.SetField(-2, "load");

            lua.PushManagedFunction(UnloadModule);
            lua.SetField(-2, "unload");

            lua.SetField(-2, "dotnet");
            lua.Pop(1);
        }
예제 #2
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext assembly_context)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                IntPtr func_int_ptr;

                unsafe
                {
                    func_int_ptr = (IntPtr)(delegate * unmanaged[Cdecl] < IntPtr, int >) & TestFunc;
                }

                lua.PushCFunction(func_int_ptr);

                lua.MCall(0, 1);

                string ret_string = lua.GetString(-1);

                lua.Pop(1);

                if (ret_string != random)
                {
                    throw new Exception("Return string is incorrect");
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
예제 #3
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext assembly_context)
        {
            TaskCompletionSource <bool> taskCompletion = new();

            try
            {
                unsafe
                {
                    lua.PushCFunction(&TestFunc);
                    lua.MCall(0, 2);

                    string ret_string = lua.GetString(-1);
                    double ret_number = lua.GetNumber(-2);

                    lua.Pop(2);

                    if (ret_string != random_string)
                    {
                        throw new Exception("Returned string is invalid");
                    }

                    if (ret_number != random_number)
                    {
                        throw new Exception("Returned number is invalid");
                    }

                    taskCompletion.TrySetResult(true);
                }
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }