示例#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);
        }
示例#2
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);
        }