Example #1
0
        public object[] DoFile(string fileName)
        {
            int errFunc = LuaAPI.load_error_func(L, errorFuncRef);

            LuaAPI.lua_pushstdcallcfunction(L, LuaStatic.traceback);
            int oldTop = LuaAPI.lua_gettop(L);

            byte[] bytes = LuaStatic.Load(fileName);
            if (bytes == null)
            {
                LuaAPI.lua_pop(L, 1);
                return(null);
            }
            if (LuaAPI.luaL_loadbuffer(L, bytes, bytes.Length, fileName) == 0)
            {
                if (LuaAPI.lua_pcall(L, 0, LuaAPI.LUA_MULTRET, errFunc) == 0)
                {
                    object[] results = translator.popValues(L, oldTop);
                    LuaAPI.lua_remove(L, errFunc);
                    LuaAPI.lua_pop(L, 1);
                    return(results);
                }
                else
                {
                    ThrowExceptionFromError(oldTop);
                    LuaAPI.lua_pop(L, 1);
                }
            }
            else
            {
                ThrowExceptionFromError(oldTop);
                LuaAPI.lua_pop(L, 1);
            }
            return(null);
        }
Example #2
0
        public static int loader(IntPtr L)
        {
            string fileName = string.Empty;

            fileName = LuaAPI.lua_tostring(L, 1);

            string lowerName = fileName.ToLower();

            if (lowerName.EndsWith(".lua"))
            {
                int index = fileName.LastIndexOf('.');
                fileName = fileName.Substring(0, index);
            }
            fileName = fileName.Replace('.', '/');
            int oldTop = LuaAPI.lua_gettop(L);

            LuaAPI.lua_pushstdcallcfunction(L, LuaStatic.traceback);

            byte[] text = LuaStatic.Load(fileName);
            if (text == null)
            {
                LuaAPI.lua_pop(L, 1);
                return(0);
            }
            if (LuaAPI.luaL_loadbuffer(L, text, text.Length, fileName) != 0)
            {
                LuaScriptMgr mgr = LuaScriptMgr.GetMgrFromLuaState(L);
                if (mgr != null)
                {
                    mgr.lua.ThrowExceptionFromError(oldTop + 1);
                }
                LuaAPI.lua_pop(L, 1);
            }
            return(1);
        }
Example #3
0
        public static int dofile(IntPtr L)
        {
            string fileName = String.Empty;

            fileName = LuaAPI.lua_tostring(L, 1);

            string lowerName = fileName.ToLower();

            if (lowerName.EndsWith(".lua"))
            {
                int index = fileName.LastIndexOf('.');
                fileName = fileName.Substring(0, index);
            }
            fileName = fileName.Replace('.', '/') + ".lua";

            int n = LuaAPI.lua_gettop(L);

            byte[] text = Load(fileName);
            if (text == null)
            {
                return(LuaAPI.lua_gettop(L) - n);
            }
            if (LuaAPI.luaL_loadbuffer(L, text, text.Length, fileName) == 0)
            {
                LuaAPI.lua_pcall(L, 0, -1, 0);
            }
            return(LuaAPI.lua_gettop(L) - n);
        }
Example #4
0
        public LuaFunction LoadString(string chunk, string name)
        {
            int oldTop = LuaAPI.lua_gettop(L);

            byte[] bt = Encoding.UTF8.GetBytes(chunk);

            if (LuaAPI.luaL_loadbuffer(L, bt, bt.Length, name) != 0)
            {
                ThrowExceptionFromError(oldTop);
            }

            LuaFunction result = translator.getFunction(L, -1);

            translator.popValues(L, oldTop);
            return(result);
        }
Example #5
0
        public object[] DoString(string chunk)
        {
            int oldTop  = LuaAPI.lua_gettop(L);
            int errFunc = LuaAPI.load_error_func(L, errorFuncRef);

            byte[] bt = Encoding.UTF8.GetBytes(chunk);
            if (LuaAPI.luaL_loadbuffer(L, bt, bt.Length, "chunk") == 0)
            {
                if (LuaAPI.lua_pcall(L, 0, LuaAPI.LUA_MULTRET, errFunc) == 0)
                {
                    LuaAPI.lua_remove(L, errFunc);
                    return(translator.popValues(L, oldTop));
                }
                else
                {
                    ThrowExceptionFromError(oldTop);
                }
            }
            else
            {
                ThrowExceptionFromError(oldTop);
            }
            return(null);
        }