Esempio n. 1
0
        //int BeginPCall()
        //{
        //    LuaDLL.lua_getglobal(L, "traceback");
        //    int oldTop = LuaDLL.lua_gettop(L);
        //    push(L);
        //    return oldTop;
        //}

        //bool PCall(int oldTop, int args)
        //{
        //    if (LuaDLL.lua_pcall(L, args, -1, -args - 2) != 0)
        //    {
        //        string err = LuaDLL.lua_tostring(L, -1);
        //        LuaDLL.lua_settop(L, oldTop);
        //        LuaDLL.lua_pop(L, 1);
        //        if (err == null) err = "Unknown Lua Error";
        //        throw new LuaScriptException(err.ToString(), "");
        //    }

        //    return true;
        //}

        //object[] EndPCall(int oldTop)
        //{
        //    object[] ret = translator.popValues(L, oldTop);
        //    LuaDLL.lua_pop(L, 1);
        //    return ret;
        //}

        //public object[] Call()
        //{
        //    int oldTop = BeginPCall();

        //    if (PCall(oldTop, 0))
        //    {
        //        return EndPCall(oldTop);
        //    }

        //    return null;
        //}

        //public object[] Call<T1>(T1 t1)
        //{
        //    int oldTop = BeginPCall();

        //    PushArgs(L, t1);

        //    if (PCall(oldTop, 1))
        //    {
        //        return EndPCall(oldTop);
        //    }

        //    return null;
        //}

        //public object[] Call<T1, T2>(T1 t1, T2 t2)
        //{
        //    int oldTop = BeginPCall();

        //    PushArgs(L, t1);
        //    PushArgs(L, t2);

        //    if (PCall(oldTop, 2))
        //    {
        //        return EndPCall(oldTop);
        //    }

        //    return null;
        //}

        //public object[] Call<T1, T2, T3>(T1 t1, T2 t2, T3 t3)
        //{
        //    int oldTop = BeginPCall();

        //    PushArgs(L, t1);
        //    PushArgs(L, t2);
        //    PushArgs(L, t3);

        //    if (PCall(oldTop, 3))
        //    {
        //        return EndPCall(oldTop);
        //    }

        //    return null;
        //}

        //public object[] Call<T1, T2, T3, T4>(T1 t1, T2 t2, T3 t3, T4 t4)
        //{
        //    int oldTop = BeginPCall();

        //    PushArgs(L, t1);
        //    PushArgs(L, t2);
        //    PushArgs(L, t3);
        //    PushArgs(L, t4);

        //    if (PCall(oldTop, 4))
        //    {
        //        return EndPCall(oldTop);
        //    }

        //    return null;
        //}

        //public object[] Call<T1, T2, T3, T4, T5>(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
        //{
        //    int oldTop = BeginPCall();

        //    PushArgs(L, t1);
        //    PushArgs(L, t2);
        //    PushArgs(L, t3);
        //    PushArgs(L, t4);
        //    PushArgs(L, t5);

        //    if (PCall(oldTop, 5))
        //    {
        //        return EndPCall(oldTop);
        //    }

        //    return null;
        //}

        void PushArgs(IntPtr L, object o)
        {
            if (o == null)
            {
                LuaScriptMgr.PushObject(L, o);
                return;
            }

            Type type = o.GetType();



            if (type.IsArray)
            {
                LuaScriptMgr.PushArray(L, o);
            }
            else if (type.IsEnum)
            {
                LuaScriptMgr.PushEnum(L, o);
            }
            else
            {
                translator.push(L, o);
            }
        }
Esempio n. 2
0
        /*
         * Pushes the object into the Lua stack according to its type.
         */
        internal void push(IntPtr luaState, object o)
        {
            if (o == null)
            {
                LuaDLL.lua_pushnil(luaState);
                return;
            }

            Type t = o.GetType();

            if (t == typeof(bool))
            {
                bool b = (bool)o;
                LuaDLL.lua_pushboolean(luaState, b);
            }
            else if (t == typeof(UnityEngine.Object))
            {
                UnityEngine.Object obj = (UnityEngine.Object)o;

                if (obj == null)
                {
                    LuaDLL.lua_pushnil(luaState);
                    return;
                }
                else
                {
                    pushObject(luaState, o, "luaNet_metatable");
                }
            }
            else if (t.IsEnum)
            {
                LuaScriptMgr.PushEnum(luaState, o);
            }
            else if (t.IsArray)
            {
                LuaScriptMgr.PushArray(luaState, o);
            }
            else if (t.IsPrimitive)
            {
                double d = Convert.ToDouble(o);
                LuaDLL.lua_pushnumber(luaState, d);
            }
            else if (t == typeof(string))
            {
                string str = (string)o;
                LuaDLL.lua_pushstring(luaState, str);
            }
            else if (IsILua(o))
            {
#if !__NOGEN__
                (((ILuaGeneratedType)o).__luaInterface_getLuaTable()).push(luaState);
#endif
            }
            else if (t == typeof(LuaTable))
            {
                ((LuaTable)o).push(luaState);
            }
            else if (t == typeof(LuaCSFunction))
            {
                pushFunction(luaState, (LuaCSFunction)o);
            }
            else if (t == typeof(LuaFunction))
            {
                ((LuaFunction)o).push(luaState);
            }
            else if (t.IsValueType)
            {
                int index = addObject(o);
                PushNewValueObject(luaState, o, index, "luaNet_metatable");
            }
            else
            {
                pushObject(luaState, o, "luaNet_metatable");
            }
        }