lua_settable() private method

private lua_settable ( IntPtr luaState, int index ) : void
luaState System.IntPtr
index int
return void
示例#1
0
        internal void setObject(int reference, object field, object val)
        {
            int newTop = LuaDLL.lua_gettop(this.L);

            LuaDLL.lua_getref(this.L, reference);
            this.translator.push(this.L, field);
            this.translator.push(this.L, val);
            LuaDLL.lua_settable(this.L, -3);
            LuaDLL.lua_settop(this.L, newTop);
        }
示例#2
0
        /*
         * Sets a numeric field of the table or userdata corresponding the the provided reference
         * to the provided value
         */
        internal void setObject(int reference, object field, object val)
        {
            int oldTop = LuaDLL.lua_gettop(L);

            LuaDLL.lua_getref(L, reference);
            translator.push(L, field);
            translator.push(L, val);
            LuaDLL.lua_settable(L, -3);
            LuaDLL.lua_settop(L, oldTop);
        }
 /*
  * Creates the metatable for delegates
  */
 private void createFunctionMetatable(IntPtr luaState)
 {
     LuaDLL.luaL_newmetatable(luaState, "luaNet_function");
     LuaDLL.lua_pushstring(luaState, "__gc");
     LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.gcFunction);
     LuaDLL.lua_settable(luaState, -3);
     LuaDLL.lua_pushstring(luaState, "__call");
     LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.execDelegateFunction);
     LuaDLL.lua_settable(luaState, -3);
     LuaDLL.lua_settop(luaState, -2);
 }
示例#4
0
        private static int CacheUserData(IntPtr L, int lo)
        {
            int result = 1;

            LuaDLL.lua_getfield(L, LuaIndexes.LUA_REGISTRYINDEX, CACHE_CSHARP_OBJECT_TABLE);
            LuaDLL.lua_pushnumber(L, objsRefId);
            LuaDLL.lua_pushvalue(L, lo);
            LuaDLL.lua_settable(L, -3);
            LuaDLL.lua_pop(L, 1);
            return(result);
        }
示例#5
0
 /*
  * Sets up the list of objects in the Lua side
  */
 private void createLuaObjectList(IntPtr luaState)
 {
     LuaDLL.lua_pushstring(luaState, "luaNet_objects");
     LuaDLL.lua_newtable(luaState);
     LuaDLL.lua_newtable(luaState);
     LuaDLL.lua_pushstring(luaState, "__mode");
     LuaDLL.lua_pushstring(luaState, "v");
     LuaDLL.lua_settable(luaState, -3);
     LuaDLL.lua_setmetatable(luaState, -2);
     LuaDLL.lua_settable(luaState, (int)LuaIndexes.LUA_REGISTRYINDEX);
 }
示例#6
0
 /*
  * Navigates a table to set the value of one of its fields
  */
 internal void setObject(string[] remainingPath, object val)
 {
     for (int i = 0; i < remainingPath.Length - 1; i++)
     {
         LuaDLL.lua_pushstring(luaState, remainingPath[i]);
         LuaDLL.lua_gettable(luaState, -2);
     }
     LuaDLL.lua_pushstring(luaState, remainingPath[remainingPath.Length - 1]);
     translator.push(luaState, val);
     LuaDLL.lua_settable(luaState, -3);
 }
 private void createLuaObjectList(IntPtr luaState)
 {
     LuaDLL.lua_pushstring(luaState, "luaNet_objects");
     LuaDLL.lua_newtable(luaState);
     LuaDLL.lua_pushvalue(luaState, -1);
     this.weakTableRef = LuaDLL.luaL_ref(luaState, LuaIndexes.LUA_REGISTRYINDEX);
     LuaDLL.lua_pushvalue(luaState, -1);
     LuaDLL.lua_setmetatable(luaState, -2);
     LuaDLL.lua_pushstring(luaState, "__mode");
     LuaDLL.lua_pushstring(luaState, "v");
     LuaDLL.lua_settable(luaState, -3);
     LuaDLL.lua_settable(luaState, LuaIndexes.LUA_REGISTRYINDEX);
 }
示例#8
0
        public static int registerTable(IntPtr luaState)
        {
#if __NOGEN__
            throwError(luaState, "Tables as Objects not implemnented");
#else
            ObjectTranslator translator = ObjectTranslator.FromState(luaState);
            if (LuaDLL.lua_type(luaState, 1) == LuaTypes.LUA_TTABLE)
            {
                LuaTable luaTable       = translator.getTable(luaState, 1);
                string   superclassName = LuaDLL.lua_tostring(luaState, 2);
                if (superclassName != null)
                {
                    Type klass = translator.FindType(superclassName);
                    if (klass != null)
                    {
                        // Creates and pushes the object in the stack, setting
                        // it as the  metatable of the first argument
                        object obj = CodeGeneration.Instance.GetClassInstance(klass, luaTable);
                        translator.pushObject(luaState, obj, "luaNet_metatable");
                        LuaDLL.lua_newtable(luaState);
                        LuaDLL.lua_pushstring(luaState, "__index");
                        LuaDLL.lua_pushvalue(luaState, -3);
                        LuaDLL.lua_settable(luaState, -3);
                        LuaDLL.lua_pushstring(luaState, "__newindex");
                        LuaDLL.lua_pushvalue(luaState, -3);
                        LuaDLL.lua_settable(luaState, -3);
                        LuaDLL.lua_setmetatable(luaState, 1);
                        // Pushes the object again, this time as the base field
                        // of the table and with the luaNet_searchbase metatable
                        LuaDLL.lua_pushstring(luaState, "base");
                        int index = translator.addObject(obj);
                        translator.pushNewObject(luaState, obj, index, "luaNet_searchbase");
                        LuaDLL.lua_rawset(luaState, 1);
                    }
                    else
                    {
                        translator.throwError(luaState, "register_table: can not find superclass '" + superclassName + "'");
                    }
                }
                else
                {
                    translator.throwError(luaState, "register_table: superclass name can not be null");
                }
            }
            else
            {
                translator.throwError(luaState, "register_table: first arg is not a table");
            }
#endif
            return(0);
        }
示例#9
0
        public static int GetComponentsInParent(IntPtr L)
        {
            int result = 1;
            int count  = LuaDLL.lua_gettop(L);

            if (count == 2 &&
                LuaStatic.CheckType(L, typeof(Type), 2))
            {
                UnityEngine.GameObject obj = LuaStatic.GetObj(L, 1) as UnityEngine.GameObject;
                object      type1          = LuaStatic.GetObj(L, 2);
                Type        arg1           = LuaStatic.GetType(type1);
                IEnumerable objs           = (IEnumerable)obj.GetComponentsInParent(arg1);
                LuaDLL.lua_newtable(L);
                int num2 = 0;
                foreach (var item in objs)
                {
                    LuaStatic.addGameObject2Lua(L, (UnityEngine.Component)item, (string)type1);
                    LuaDLL.lua_pushnumber(L, (double)(++num2));
                    LuaDLL.lua_insert(L, -2);
                    LuaDLL.lua_settable(L, -3);
                }

                return(result);
            }
            if (count == 3 &&
                LuaStatic.CheckType(L, typeof(Type), 2) &&
                LuaStatic.CheckType(L, typeof(Boolean), 3))
            {
                UnityEngine.GameObject obj = LuaStatic.GetObj(L, 1) as UnityEngine.GameObject;
                object      type1          = LuaStatic.GetObj(L, 2);
                Type        arg1           = LuaStatic.GetType(type1);
                Boolean     arg2           = (Boolean)LuaStatic.GetObj(L, 3);
                IEnumerable objs           = (IEnumerable)obj.GetComponentsInParent(arg1, arg2);
                LuaDLL.lua_newtable(L);
                int num2 = 0;
                foreach (var item in objs)
                {
                    LuaStatic.addGameObject2Lua(L, (UnityEngine.Component)item, "Component");
                    LuaDLL.lua_pushnumber(L, (double)(++num2));
                    LuaDLL.lua_insert(L, -2);
                    LuaDLL.lua_settable(L, -3);
                }

                return(result);
            }
            LuaStatic.traceback(L, "count not enough");
            LuaDLL.lua_error(L);
            return(result);
        }
示例#10
0
 /*
  * Creates the metatable for superclasses (the base
  * field of registered tables)
  */
 private void createBaseClassMetatable(IntPtr luaState)
 {
     LuaDLL.luaL_newmetatable(luaState, "luaNet_searchbase");
     LuaDLL.lua_pushstring(luaState, "__gc");
     LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.gcFunction);
     LuaDLL.lua_settable(luaState, -3);
     LuaDLL.lua_pushstring(luaState, "__tostring");
     LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.toStringFunction);
     LuaDLL.lua_settable(luaState, -3);
     LuaDLL.lua_pushstring(luaState, "__index");
     LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.baseIndexFunction);
     LuaDLL.lua_settable(luaState, -3);
     LuaDLL.lua_pushstring(luaState, "__newindex");
     LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.newindexFunction);
     LuaDLL.lua_settable(luaState, -3);
     LuaDLL.lua_settop(luaState, -2);
 }
示例#11
0
        public static int LoadAll(IntPtr L)
        {
            int result = 1;
            int count  = LuaDLL.lua_gettop(L);

            if (count == 3 &&
                LuaStatic.CheckType(L, typeof(String), 2) &&
                LuaStatic.CheckType(L, typeof(Type), 3))
            {
                String      arg1  = (String)LuaStatic.GetObj(L, 2);
                object      type2 = LuaStatic.GetObj(L, 3);
                Type        arg2  = LuaStatic.GetType(type2);
                IEnumerable objs  = (IEnumerable)UnityEngine.Resources.LoadAll(arg1, arg2);
                LuaDLL.lua_newtable(L);
                int num2 = 0;
                foreach (var item in objs)
                {
                    LuaStatic.addGameObject2Lua(L, (UnityEngine.Object)item, (string)type2);
                    LuaDLL.lua_pushnumber(L, (double)(++num2));
                    LuaDLL.lua_insert(L, -2);
                    LuaDLL.lua_settable(L, -3);
                }

                return(result);
            }
            if (count == 2 &&
                LuaStatic.CheckType(L, typeof(String), 2))
            {
                String      arg1 = (String)LuaStatic.GetObj(L, 2);
                IEnumerable objs = (IEnumerable)UnityEngine.Resources.LoadAll(arg1);
                LuaDLL.lua_newtable(L);
                int num2 = 0;
                foreach (var item in objs)
                {
                    LuaStatic.addGameObject2Lua(L, (UnityEngine.Object)item, "Object");
                    LuaDLL.lua_pushnumber(L, (double)(++num2));
                    LuaDLL.lua_insert(L, -2);
                    LuaDLL.lua_settable(L, -3);
                }

                return(result);
            }
            LuaStatic.traceback(L, "count not enough");
            LuaDLL.lua_error(L);
            return(result);
        }
 /*
  * Implementation of make_object. Registers a table (first
  * argument in the stack) as an object subclassing the
  * type passed as second argument in the stack.
  */
 private int registerTable(KopiLua.Lua.lua_State luaState)
 {
     if (LuaDLL.lua_type(luaState, 1) == LuaTypes.LUA_TTABLE)
     {
         LuaTable luaTable       = getTable(luaState, 1);
         string   superclassName = LuaDLL.lua_tostring(luaState, 2);
         if (superclassName != null)
         {
             Type klass = FindType(superclassName);
             if (klass != null)
             {
                 // Creates and pushes the object in the stack, setting
                 // it as the  metatable of the first argument
                 object obj = CodeGeneration.Instance.GetClassInstance(klass, luaTable);
                 pushObject(luaState, obj, "luaNet_metatable");
                 LuaDLL.lua_newtable(luaState);
                 LuaDLL.lua_pushstring(luaState, "__index");
                 LuaDLL.lua_pushvalue(luaState, -3);
                 LuaDLL.lua_settable(luaState, -3);
                 LuaDLL.lua_pushstring(luaState, "__newindex");
                 LuaDLL.lua_pushvalue(luaState, -3);
                 LuaDLL.lua_settable(luaState, -3);
                 LuaDLL.lua_setmetatable(luaState, 1);
                 // Pushes the object again, this time as the base field
                 // of the table and with the luaNet_searchbase metatable
                 LuaDLL.lua_pushstring(luaState, "base");
                 int index = addObject(obj);
                 pushNewObject(luaState, obj, index, "luaNet_searchbase");
                 LuaDLL.lua_rawset(luaState, 1);
             }
             else
             {
                 throwError(luaState, "register_table: can not find superclass '" + superclassName + "'");
             }
         }
         else
         {
             throwError(luaState, "register_table: superclass name can not be null");
         }
     }
     else
     {
         throwError(luaState, "register_table: first arg is not a table");
     }
     return(0);
 }
        public static int registerTable(IntPtr luaState)
        {
            ObjectTranslator objectTranslator = ObjectTranslator.FromState(luaState);

            if (LuaDLL.lua_type(luaState, 1) == LuaTypes.LUA_TTABLE)
            {
                LuaTable table = objectTranslator.getTable(luaState, 1);
                string   text  = LuaDLL.lua_tostring(luaState, 2);
                if (text != null)
                {
                    Type type = objectTranslator.FindType(text);
                    if (type != null)
                    {
                        object classInstance = CodeGeneration.Instance.GetClassInstance(type, table);
                        objectTranslator.pushObject(luaState, classInstance, "luaNet_metatable");
                        LuaDLL.lua_newtable(luaState);
                        LuaDLL.lua_pushstring(luaState, "__index");
                        LuaDLL.lua_pushvalue(luaState, -3);
                        LuaDLL.lua_settable(luaState, -3);
                        LuaDLL.lua_pushstring(luaState, "__newindex");
                        LuaDLL.lua_pushvalue(luaState, -3);
                        LuaDLL.lua_settable(luaState, -3);
                        LuaDLL.lua_setmetatable(luaState, 1);
                        LuaDLL.lua_pushstring(luaState, "base");
                        int index = objectTranslator.addObject(classInstance);
                        objectTranslator.pushNewObject(luaState, classInstance, index, "luaNet_searchbase");
                        LuaDLL.lua_rawset(luaState, 1);
                    }
                    else
                    {
                        objectTranslator.throwError(luaState, "register_table: can not find superclass '" + text + "'");
                    }
                }
                else
                {
                    objectTranslator.throwError(luaState, "register_table: superclass name can not be null");
                }
            }
            else
            {
                objectTranslator.throwError(luaState, "register_table: first arg is not a table");
            }
            return(0);
        }
示例#14
0
 /*
  * Creates the metatable for type references
  */
 private void createClassMetatable(IntPtr luaState)
 {
     LuaDLL.luaL_newmetatable(luaState, "luaNet_class");
     LuaDLL.lua_pushstring(luaState, "__gc");
     LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.gcFunction);
     LuaDLL.lua_settable(luaState, -3);
     LuaDLL.lua_pushstring(luaState, "__tostring");
     LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.toStringFunction);
     LuaDLL.lua_settable(luaState, -3);
     LuaDLL.lua_pushstring(luaState, "__index");
     LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.classIndexFunction);
     LuaDLL.lua_settable(luaState, -3);
     LuaDLL.lua_pushstring(luaState, "__newindex");
     LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.classNewindexFunction);
     LuaDLL.lua_settable(luaState, -3);
     LuaDLL.lua_pushstring(luaState, "__call");
     LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.callConstructorFunction);
     LuaDLL.lua_settable(luaState, -3);
     LuaDLL.lua_settop(luaState, -2);
 }
示例#15
0
        public static int FindGameObjectsWithTag(IntPtr L)
        {
            int result = 1;
            int count  = LuaDLL.lua_gettop(L);

            String      arg1 = (String)LuaStatic.GetObj(L, 2);
            IEnumerable objs = (IEnumerable)UnityEngine.GameObject.FindGameObjectsWithTag(arg1);

            LuaDLL.lua_newtable(L);
            int num2 = 0;

            foreach (var item in objs)
            {
                LuaStatic.addGameObject2Lua(L, (UnityEngine.GameObject)item, "GameObject");
                LuaDLL.lua_pushnumber(L, (double)(++num2));
                LuaDLL.lua_insert(L, -2);
                LuaDLL.lua_settable(L, -3);
            }
            return(result);
        }
示例#16
0
        public static int FindObjectsOfType(IntPtr L)
        {
            int result = 1;
            int count  = LuaDLL.lua_gettop(L);

            object      type1 = LuaStatic.GetObj(L, 2);
            Type        arg1  = LuaStatic.GetType(type1);
            IEnumerable objs  = (IEnumerable)UnityEngine.Object.FindObjectsOfType(arg1);

            LuaDLL.lua_newtable(L);
            int num2 = 0;

            foreach (var item in objs)
            {
                LuaStatic.addGameObject2Lua(L, (UnityEngine.Object)item, (string)type1);
                LuaDLL.lua_pushnumber(L, (double)(++num2));
                LuaDLL.lua_insert(L, -2);
                LuaDLL.lua_settable(L, -3);
            }
            return(result);
        }
示例#17
0
        public static int unregisterTable(IntPtr luaState)
        {
            ObjectTranslator translator = ObjectTranslator.FromState(luaState);

            try
            {
                if (LuaDLL.lua_getmetatable(luaState, 1) != 0)
                {
                    LuaDLL.lua_pushstring(luaState, "__index");
                    LuaDLL.lua_gettable(luaState, -2);
                    object obj = translator.getRawNetObject(luaState, -1);
                    if (obj == null)
                    {
                        translator.throwError(luaState, "unregister_table: arg is not valid table");
                    }
                    FieldInfo luaTableField = obj.GetType().GetField("__luaInterface_luaTable");
                    if (luaTableField == null)
                    {
                        translator.throwError(luaState, "unregister_table: arg is not valid table");
                    }
                    luaTableField.SetValue(obj, null);
                    LuaDLL.lua_pushnil(luaState);
                    LuaDLL.lua_setmetatable(luaState, 1);
                    LuaDLL.lua_pushstring(luaState, "base");
                    LuaDLL.lua_pushnil(luaState);
                    LuaDLL.lua_settable(luaState, 1);
                }
                else
                {
                    translator.throwError(luaState, "unregister_table: arg is not valid table");
                }
            }
            catch (Exception e)
            {
                translator.throwError(luaState, e.Message);
            }
            return(0);
        }
示例#18
0
        public Lua(bool enableLengthWorkaround)
        {
            // NOTE: You should enable the length workaround on Mac and Linux
            this.enableLengthWorkaround = enableLengthWorkaround;

            luaState = LuaDLL.luaL_newstate();  // steffenj: Lua 5.1.1 API change (lua_open is gone)

            // Load libraries
            LuaDLL.luaL_openlibs(luaState);

            // Add LuaInterface marker
            LuaDLL.lua_pushstring(luaState, "LUAINTERFACE LOADED");
            LuaDLL.lua_pushboolean(luaState, true);
            LuaDLL.lua_settable(luaState, (int)LuaIndexes.LUA_REGISTRYINDEX);

            translator = new ObjectTranslator(this, luaState);

            tracebackFunction = new LuaCSFunction(traceback);

            // We need to keep this in a managed reference so the delegate doesn't get garbage collected
            panicCallback = new LuaFunctionCallback(PanicCallback);
            LuaDLL.lua_atpanic(luaState, panicCallback);
        }
示例#19
0
        public Lua()
        {
            luaState   = LuaDLL.luaL_newstate();
            translator = new ObjectTranslator(this, luaState);

            LuaDLL.luaL_openlibs(luaState);
            LuaDLL.lua_pushstring(luaState, "LUAINTERFACE LOADED");
            LuaDLL.lua_pushboolean(luaState, true);
            LuaDLL.lua_settable(luaState, (int)LuaIndexes.LUA_REGISTRYINDEX);
            LuaDLL.lua_newtable(luaState);
            LuaDLL.lua_setglobal(luaState, "luanet");
            LuaDLL.lua_pushvalue(luaState, (int)LuaIndexes.LUA_GLOBALSINDEX);
            LuaDLL.lua_getglobal(luaState, "luanet");
            LuaDLL.lua_pushstring(luaState, "getmetatable");
            LuaDLL.lua_getglobal(luaState, "getmetatable");
            LuaDLL.lua_settable(luaState, -3);
            LuaDLL.lua_replace(luaState, (int)LuaIndexes.LUA_GLOBALSINDEX);
            LuaDLL.lua_replace(luaState, (int)LuaIndexes.LUA_GLOBALSINDEX);
            LuaDLL.luaL_dostring(luaState, Lua.init_luanet);

            panicCallback = new LuaCSFunction(PanicCallback);
            LuaDLL.lua_atpanic(luaState, panicCallback);
        }
示例#20
0
        /*
         * Creates a new table as a global variable or as a field
         * inside an existing table
         */
        public void NewTable(string fullPath)
        {
            string[] path   = fullPath.Split('.');
            int      oldTop = LuaDLL.lua_gettop(L);

            if (path.Length == 1)
            {
                LuaDLL.lua_newtable(L);
                LuaDLL.lua_setglobal(L, fullPath);
            }
            else
            {
                LuaDLL.lua_getglobal(L, path[0]);
                for (int i = 1; i < path.Length - 1; i++)
                {
                    LuaDLL.lua_pushstring(L, path[i]);
                    LuaDLL.lua_gettable(L, -2);
                }
                LuaDLL.lua_pushstring(L, path[path.Length - 1]);
                LuaDLL.lua_newtable(L);
                LuaDLL.lua_settable(L, -3);
            }
            LuaDLL.lua_settop(L, oldTop);
        }
示例#21
0
        /*
         * Creates a new table as a global variable or as a field
         * inside an existing table
         */
        public void NewTable(string fullPath)
        {
            string[] path   = fullPath.Split(new char[] { '.' });
            int      oldTop = LuaDLL.lua_gettop(luaState);

            if (path.Length == 1)
            {
                LuaDLL.lua_newtable(luaState);
                LuaDLL.lua_setglobal(luaState, fullPath);
            }
            else
            {
                LuaDLL.lua_getglobal(luaState, path[0]);
                for (int i = 1; i < path.Length - 1; i++)
                {
                    LuaDLL.lua_pushstring(luaState, path[i]);
                    LuaDLL.lua_gettable(luaState, -2);
                }
                LuaDLL.lua_pushstring(luaState, path[path.Length - 1]);
                LuaDLL.lua_newtable(luaState);
                LuaDLL.lua_settable(luaState, -3);
            }
            LuaDLL.lua_settop(luaState, oldTop);
        }
 /*
  * Implementation of free_object. Clears the metatable and the
  * base field, freeing the created object for garbage-collection
  */
 private int unregisterTable(KopiLua.Lua.lua_State luaState)
 {
     try
     {
         if (LuaDLL.lua_getmetatable(luaState, 1) != 0)
         {
             LuaDLL.lua_pushstring(luaState, "__index");
             LuaDLL.lua_gettable(luaState, -2);
             object obj = getRawNetObject(luaState, -1);
             if (obj == null)
             {
                 throwError(luaState, "unregister_table: arg is not valid table");
             }
             FieldInfo luaTableField = obj.GetType().GetField("__luaInterface_luaTable");
             if (luaTableField == null)
             {
                 throwError(luaState, "unregister_table: arg is not valid table");
             }
             luaTableField.SetValue(obj, null);
             LuaDLL.lua_pushnil(luaState);
             LuaDLL.lua_setmetatable(luaState, 1);
             LuaDLL.lua_pushstring(luaState, "base");
             LuaDLL.lua_pushnil(luaState);
             LuaDLL.lua_settable(luaState, 1);
         }
         else
         {
             throwError(luaState, "unregister_table: arg is not valid table");
         }
     }
     catch (Exception e)
     {
         throwError(luaState, e.Message);
     }
     return(0);
 }
示例#23
0
文件: Lua.cs 项目: weimingtom/pap2
        public Lua()
        {
            luaState = LuaDLL.luaL_newstate();                  // steffenj: Lua 5.1.1 API change (lua_open is gone)
            //LuaDLL.luaopen_base(luaState);	// steffenj: luaopen_* no longer used
            LuaDLL.luaL_openlibs(luaState);                     // steffenj: Lua 5.1.1 API change (luaopen_base is gone, just open all libs right here)
            LuaDLL.lua_pushstring(luaState, "LUAINTERFACE LOADED");
            LuaDLL.lua_pushboolean(luaState, true);
            LuaDLL.lua_settable(luaState, LuaIndexes.LUA_REGISTRYINDEX);
            LuaDLL.lua_newtable(luaState);
            LuaDLL.lua_setglobal(luaState, "luanet");
            LuaDLL.lua_pushvalue(luaState, LuaIndexes.LUA_GLOBALSINDEX);
            LuaDLL.lua_getglobal(luaState, "luanet");
            LuaDLL.lua_pushstring(luaState, "getmetatable");
            LuaDLL.lua_getglobal(luaState, "getmetatable");
            LuaDLL.lua_settable(luaState, -3);
            LuaDLL.lua_replace(luaState, LuaIndexes.LUA_GLOBALSINDEX);
            translator = new ObjectTranslator(this, luaState);
            LuaDLL.lua_replace(luaState, LuaIndexes.LUA_GLOBALSINDEX);
            LuaDLL.luaL_dostring(luaState, Lua.init_luanet);                    // steffenj: lua_dostring renamed to luaL_dostring

            // We need to keep this in a managed reference so the delegate doesn't get garbage collected
            panicCallback = new LuaFunctionCallback(PanicCallback);
            LuaDLL.lua_atpanic(luaState, panicCallback);
        }
示例#24
0
        public LuaState()
        {
            // Create State
            L = LuaDLL.luaL_newstate();

            // Create LuaInterface library
            LuaDLL.luaL_openlibs(L);
            LuaDLL.lua_pushstring(L, "LUAINTERFACE LOADED");
            LuaDLL.lua_pushboolean(L, true);
            LuaDLL.lua_settable(L, (int)LuaIndexes.LUA_REGISTRYINDEX);
            LuaDLL.lua_newtable(L);

            LuaDLL.lua_setglobal(L, "luanet");
            LuaDLL.lua_pushvalue(L, (int)LuaIndexes.LUA_GLOBALSINDEX);  //鍘嬪叆浜哶G琛?
            LuaDLL.lua_getglobal(L, "luanet");
            LuaDLL.lua_pushstring(L, "getmetatable");
            LuaDLL.lua_getglobal(L, "getmetatable");
            LuaDLL.lua_settable(L, -3);
            LuaDLL.lua_pushstring(L, "rawget");
            LuaDLL.lua_getglobal(L, "rawget");
            LuaDLL.lua_settable(L, -3);
            LuaDLL.lua_pushstring(L, "rawset");
            LuaDLL.lua_getglobal(L, "rawset");
            LuaDLL.lua_settable(L, -3);

            // Set luanet as global for object translator
            LuaDLL.lua_replace(L, (int)LuaIndexes.LUA_GLOBALSINDEX); //鐢╨uanet鏇挎崲_G琛?
            translator = new ObjectTranslator(this, L);
            LuaDLL.lua_replace(L, (int)LuaIndexes.LUA_GLOBALSINDEX); //鎭㈠_G琛?

            translator.PushTranslator(L);

            // We need to keep this in a managed reference so the delegate doesn't get garbage collected
            panicCallback = new LuaCSFunction(LuaStatic.panic);
            LuaDLL.lua_atpanic(L, panicCallback);

            printFunction = new LuaCSFunction(LuaStatic.print);
            LuaDLL.lua_pushstdcallcfunction(L, printFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "lprint");

            warnFunction = new LuaCSFunction(LuaStatic.warn);
            LuaDLL.lua_pushstdcallcfunction(L, warnFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "lwarn");

            breakFunction = new LuaCSFunction(LuaStatic.breakFunc);
            LuaDLL.lua_pushstdcallcfunction(L, breakFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "breakpoint");

            loadfileFunction = new LuaCSFunction(LuaStatic.loadfile);
            LuaDLL.lua_pushstdcallcfunction(L, loadfileFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "loadfile");

            dofileFunction = new LuaCSFunction(LuaStatic.dofile);
            LuaDLL.lua_pushstdcallcfunction(L, dofileFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "dofile");

            pcallFunction = new LuaCSFunction(LuaStatic.pcall);
            LuaDLL.lua_pushstdcallcfunction(L, pcallFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "pcall");

            LuaDLL.lua_pushstdcallcfunction(L, LuaStatic.errorFunc_traceback);
            errorFuncRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);

            // Insert our loader FIRST
            loaderFunction = new LuaCSFunction(LuaStatic.loader);
            LuaDLL.lua_pushstdcallcfunction(L, loaderFunction);
            int loaderFunc = LuaDLL.lua_gettop(L);

            LuaDLL.lua_getfield(L, LuaIndexes.LUA_GLOBALSINDEX, "package");
            LuaDLL.lua_getfield(L, -1, "loaders");
            int loaderTable = LuaDLL.lua_gettop(L);

            // Shift table elements right
            for (int e = LuaDLL.luaL_getn(L, loaderTable) + 1; e > 1; e--)
            {
                LuaDLL.lua_rawgeti(L, loaderTable, e - 1);
                LuaDLL.lua_rawseti(L, loaderTable, e);
            }
            LuaDLL.lua_pushvalue(L, loaderFunc);
            LuaDLL.lua_rawseti(L, loaderTable, 1);
            LuaDLL.lua_settop(L, 0);

            DoString(LuaStatic.init_luanet);
            tracebackFunction = new LuaCSFunction(LuaStatic.traceback);
        }
示例#25
0
        public LuaState()
        {
            // Create State
            L = LuaDLL.luaL_newstate();

            // Create LuaInterface library
            LuaDLL.luaL_openlibs(L);
            LuaDLL.lua_pushstring(L, "LUAINTERFACE LOADED");
            LuaDLL.lua_pushboolean(L, true);
            LuaDLL.lua_settable(L, (int)LuaIndexes.LUA_REGISTRYINDEX);
            LuaDLL.lua_newtable(L);
            LuaDLL.lua_setglobal(L, "luanet");
            LuaDLL.lua_pushvalue(L, (int)LuaIndexes.LUA_GLOBALSINDEX);
            LuaDLL.lua_getglobal(L, "luanet");
            LuaDLL.lua_pushstring(L, "getmetatable");
            LuaDLL.lua_getglobal(L, "getmetatable");
            LuaDLL.lua_settable(L, -3);

            // Set luanet as global for object translator
            LuaDLL.lua_replace(L, (int)LuaIndexes.LUA_GLOBALSINDEX);
            translator = new ObjectTranslator(this, L);
            LuaDLL.lua_replace(L, (int)LuaIndexes.LUA_GLOBALSINDEX);

            GCHandle handle  = GCHandle.Alloc(translator, GCHandleType.Pinned);
            IntPtr   thisptr = GCHandle.ToIntPtr(handle);

            LuaDLL.lua_pushlightuserdata(L, thisptr);
            LuaDLL.lua_setglobal(L, "_translator");

            // We need to keep this in a managed reference so the delegate doesn't get garbage collected
            panicCallback = new LuaCSFunction(LuaStatic.panic);
            LuaDLL.lua_atpanic(L, panicCallback);

            printFunction = new LuaCSFunction(LuaStatic.print);
            LuaDLL.lua_pushstdcallcfunction(L, printFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "print");

            loadfileFunction = new LuaCSFunction(LuaStatic.loadfile);
            LuaDLL.lua_pushstdcallcfunction(L, loadfileFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "loadfile");

            dofileFunction = new LuaCSFunction(LuaStatic.dofile);
            LuaDLL.lua_pushstdcallcfunction(L, dofileFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "dofile");

            // Insert our loader FIRST
            loaderFunction = new LuaCSFunction(LuaStatic.loader);
            LuaDLL.lua_pushstdcallcfunction(L, loaderFunction);
            int loaderFunc = LuaDLL.lua_gettop(L);

            LuaDLL.lua_getfield(L, LuaIndexes.LUA_GLOBALSINDEX, "package");
            LuaDLL.lua_getfield(L, -1, "loaders");
            int loaderTable = LuaDLL.lua_gettop(L);

            // Shift table elements right
            for (int e = LuaDLL.luaL_getn(L, loaderTable) + 1; e > 1; e--)
            {
                LuaDLL.lua_rawgeti(L, loaderTable, e - 1);
                LuaDLL.lua_rawseti(L, loaderTable, e);
            }
            LuaDLL.lua_pushvalue(L, loaderFunc);
            LuaDLL.lua_rawseti(L, loaderTable, 1);
            LuaDLL.lua_settop(L, 0);

            DoString(LuaStatic.init_luanet);
            tracebackFunction = new LuaCSFunction(LuaStatic.traceback);
        }
示例#26
0
 public void LuaSetTable(int idx)
 {
     LuaDLL.lua_settable(L, idx);
 }
示例#27
0
文件: LuaDLL.cs 项目: laukey/slua
 public static void lua_setglobal(IntPtr luaState, string name)
 {
     LuaDLL.lua_pushstring(luaState, name);
     LuaDLL.lua_insert(luaState, -2);
     LuaDLL.lua_settable(luaState, LuaIndexes.LUA_GLOBALSINDEX);
 }