Beispiel #1
0
        internal static object _ParseLuaValue(LuaState luaState, int index)
        {
            try {
                var t = LuaLib.LuaType(luaState, index);
                switch (t)
                {
                case LuaTypes.Nil:
                    return(null);

                case LuaTypes.Boolean:
                    return(LuaLib.LuaToBoolean(luaState, index));

                case LuaTypes.Number:
                    return(LuaLib.LuaToNumber(luaState, index));

                case LuaTypes.String:
                    return(new LuaString(LuaLib.LuaToBytes(luaState, index)));

                case LuaTypes.Function:
                    LuaLib.LuaPushValue(luaState, index);
                    int reference = LuaLib.LuaRef(luaState, 1);
                    return(-1 == reference ? null : new LuaFunction(reference));

                case LuaTypes.UserData:
                    var allocId = LuaLib.LuaNetRawNetObj(luaState, index);
                    if (LuaExecuter.backObjects.ContainsKey(allocId))
                    {
                        return(LuaExecuter.backObjects[allocId]);
                    }
                    else
                    {
                        return(null);
                    }

                case LuaTypes.Table:
                    LuaLib.LuaPushValue(luaState, index);
                    reference = LuaLib.LuaRef(luaState, 1);
                    if (-1 == reference)
                    {
                        return(null);
                    }
                    return(new LuaTable(luaState, reference));
                }
            } catch (Exception e) {
                Logger <ILuaRuntime> .X(e);
            }

            return(null);
        }
Beispiel #2
0
        internal static int _CollectObject(LuaState luaState)
        {
            var    allocId = LuaLib.LuaNetRawNetObj(luaState, 1);
            object o       = null;

            if (LuaExecuter.backObjects.TryGetValue(allocId, out o))
            {
                if (0 == (LuaExecuter.objectRefs[o] -= 1))
                {
                    LuaExecuter.objects.Remove(o);
                    LuaExecuter.objectRefs.Remove(o);
                    LuaExecuter.backObjects.Remove(allocId);
                }
            }

            return(0);
        }