Esempio n. 1
0
    private Sio.SData format_map(IntPtr L, int index, NParam o)
    {
        Sio.SMapWriter pmap = new Sio.SMapWriter();
        Sio.SData      data = new Sio.SData(pmap);

        if (LuaAPI.lua_istable(L, index) && o.DType == ParamType.ptype_object)
        {
            NStruct ps = NStructManager.GetInstance().Find(o.TypeName);
            if (ps != null)
            {
                LuaAPI.lua_pushnil(L);
                while (LuaAPI.lua_next(L, index) != 0)
                {
                    if (LuaAPI.lua_isstring(L, -2))
                    {
                        NParam findparam = ps.Get(LuaAPI.lua_tostring(L, -2));
                        if (findparam != null)
                        {
                            pmap.write(findparam.Id, format_data(findparam, L, LuaAPI.lua_gettop(L), true));
                        }
                    }
                    LuaAPI.lua_pop(L, 1);
                }
            }
        }
        return(data);
    }
Esempio n. 2
0
 private Sio.SData format_List(IntPtr L, int index, NParam o)
 {
     Sio.SListWriter pl = new Sio.SListWriter();
     Sio.SData       d  = new Sio.SData(pl);
     if (LuaAPI.lua_istable(L, index))
     {
         int indexsize = (int)LuaAPI.xlua_objlen(L, index);
         for (int list_index = 1; list_index <= indexsize; ++list_index)
         {
             LuaAPI.xlua_rawgeti(L, index, list_index);
             Sio.SData td = format_data(o, L, LuaAPI.lua_gettop(L), false);
             pl.add(td);
             LuaAPI.lua_pop(L, 1);
         }
     }
     return(d);
 }
Esempio n. 3
0
        private int LuaUsing(IntPtr l)
        {
            try
            {
                LuaDLL.luaL_checktype(l, 1, LuaTypes.LUA_TSTRING);
                string str = LuaDLL.lua_tostring(l, 1);

                string[] ns = str.Split('.');

                LuaDLL.lua_pushglobaltable(l);

                for (int n = 0; n < ns.Length; n++)
                {
                    LuaDLL.lua_getfield(l, -1, ns[n]);
                    if (!LuaDLL.lua_istable(l, -1))
                    {
                        return(LuaObject.error(l, "expect {0} is type table", ns));
                    }
                    LuaDLL.lua_remove(l, -2);
                }

                LuaDLL.lua_pushnil(l);
                while (LuaDLL.lua_next(l, -2) != 0)
                {
                    string key = LuaDLL.lua_tostring(l, -2);
                    LuaDLL.lua_getglobal(l, key);
                    if (!LuaDLL.lua_isnil(l, -1))
                    {
                        LuaDLL.lua_pop(l, 1);
                        return(LuaObject.error(l, "{0} had existed, import can't overload it.", key));
                    }
                    LuaDLL.lua_pop(l, 1);
                    LuaDLL.lua_setglobal(l, key);
                }

                LuaDLL.lua_pop(l, 1);

                LuaObject.pushValue(l, true);
                return(1);
            }
            catch (Exception e)
            {
                return(LuaObject.error(l, e));
            }
        }