Esempio n. 1
0
 public static int Error(IntPtr ptr, string err, params object[] args)
 {
     err = string.Format(err, args);
     LuaNativeMethods.lua_pushboolean(ptr, false);
     LuaNativeMethods.lua_pushstring(ptr, err);
     return(2);
 }
Esempio n. 2
0
        public static int ProtectedCall(IntPtr ptr)
        {
            int status;

            if (LuaNativeMethods.lua_type(ptr, 1) != LuaTypes.TYPE_FUNCTION)
            {
                return(LuaObject.Error(ptr, "arg 1 expect function"));
            }

            LuaNativeMethods.luaL_checktype(ptr, 1, LuaTypes.TYPE_FUNCTION);
            status = LuaNativeMethods.lua_pcall(ptr, LuaNativeMethods.lua_gettop(ptr) - 1, LuaNativeMethods.LUAMultRet, 0);
            LuaNativeMethods.lua_pushboolean(ptr, status == 0);
            LuaNativeMethods.lua_insert(ptr, 1);
            return(LuaNativeMethods.lua_gettop(ptr));  /* return status + all results */
        }
Esempio n. 3
0
 public static void PushValue(IntPtr ptr, bool b)
 {
     LuaNativeMethods.lua_pushboolean(ptr, b);
 }
Esempio n. 4
0
        public void SetupPushVar()
        {
            typePushMap[typeof(float)] = (IntPtr ptr, object o) =>
            {
                LuaNativeMethods.lua_pushnumber(ptr, (float)o);
            };

            typePushMap[typeof(double)] = (IntPtr ptr, object o) =>
            {
                LuaNativeMethods.lua_pushnumber(ptr, (double)o);
            };

            typePushMap[typeof(int)] =
                (IntPtr ptr, object o) =>
            {
                LuaNativeMethods.lua_pushinteger(ptr, (int)o);
            };

            typePushMap[typeof(uint)] =
                (IntPtr ptr, object o) =>
            {
                LuaNativeMethods.lua_pushnumber(ptr, Convert.ToUInt32(o));
            };

            typePushMap[typeof(short)] =
                (IntPtr ptr, object o) =>
            {
                LuaNativeMethods.lua_pushinteger(ptr, (short)o);
            };

            typePushMap[typeof(ushort)] =
                (IntPtr ptr, object o) =>
            {
                LuaNativeMethods.lua_pushinteger(ptr, (ushort)o);
            };

            typePushMap[typeof(sbyte)] =
                (IntPtr ptr, object o) =>
            {
                LuaNativeMethods.lua_pushinteger(ptr, (sbyte)o);
            };

            typePushMap[typeof(byte)] =
                (IntPtr ptr, object o) =>
            {
                LuaNativeMethods.lua_pushinteger(ptr, (byte)o);
            };

            typePushMap[typeof(long)]      =
                typePushMap[typeof(ulong)] =
                    (IntPtr ptr, object o) =>
            {
#if LUA_5_3
                LuaNativeMethods.lua_pushinteger(ptr, (long)o);
#else
                LuaNativeMethods.lua_pushnumber(ptr, System.Convert.ToDouble(o));
#endif
            };

            typePushMap[typeof(string)] = (IntPtr ptr, object o) =>
            {
                LuaNativeMethods.lua_pushstring(ptr, (string)o);
            };

            typePushMap[typeof(bool)] = (IntPtr ptr, object o) =>
            {
                LuaNativeMethods.lua_pushboolean(ptr, (bool)o);
            };

            typePushMap[typeof(LuaTable)]          =
                typePushMap[typeof(LuaFunction)]   =
                    typePushMap[typeof(LuaThread)] =
                        (IntPtr ptr, object o) =>
            {
                ((LuaVar)o).Push(ptr);
            };

            typePushMap[typeof(LuaCSFunction)] = (IntPtr ptr, object o) =>
            {
                LuaObject.PushValue(ptr, (LuaCSFunction)o);
            };
        }
Esempio n. 5
0
 public static int Ok(IntPtr ptr, int retCount)
 {
     LuaNativeMethods.lua_pushboolean(ptr, true);
     LuaNativeMethods.lua_insert(ptr, -(retCount + 1));
     return(retCount + 1);
 }
Esempio n. 6
0
 public static int Ok(IntPtr ptr)
 {
     LuaNativeMethods.lua_pushboolean(ptr, true);
     return(1);
 }
Esempio n. 7
0
 public static int Error(IntPtr ptr, string err)
 {
     LuaNativeMethods.lua_pushboolean(ptr, false);
     LuaNativeMethods.lua_pushstring(ptr, err);
     return(2);
 }
Esempio n. 8
0
 public static int Error(IntPtr ptr, Exception e)
 {
     LuaNativeMethods.lua_pushboolean(ptr, false);
     LuaNativeMethods.lua_pushstring(ptr, e.ToString());
     return(2);
 }