예제 #1
0
        private static int _DoFileCallback(LuaState luaState)
        {
            // Use asset manager to replace original dofile process.
            // - mouguangyi
            try {
                var fileName = LuaLib.LuaToString(luaState, 1);
                using (var asset = ServiceCenter.GetService <IAssetManager>().Load(fileName + ".txt", AssetType.BYTES)) {
                    var chunk = asset.Cast <byte[]>();
                    if (null == chunk)
                    {
                        throw new Exception("Can't load lua script: " + fileName);
                    }
                    else
                    {
                        int oldTop = LuaLib.LuaGetTop(luaState);
                        if (0 == LuaLib.LuaLLoadBuffer(luaState, chunk, fileName))
                        {
                            if (0 != LuaLib.LuaPCall(luaState, 0, -1, 0))
                            {
                                _ThrowExceptionFromError(luaState, oldTop);
                            }
                        }
                        else
                        {
                            _ThrowExceptionFromError(luaState, oldTop);
                        }
                    }
                }
            } catch (Exception e) {
                Logger <ILuaRuntime> .X(e);
            }

            return(0);
        }
예제 #2
0
        public object[] DoFile(string fileName)
        {
            // Use asset manager to replace original load file process.
            // - mouguangyi
            try {
                using (var asset = ServiceCenter.GetService <IAssetManager>().Load(fileName + ".txt", AssetType.BYTES)) {
                    var chunk = asset.Cast <byte[]>();
                    if (null == chunk)
                    {
                        throw new Exception("Can't load lua script: " + fileName);
                    }
                    else
                    {
                        int oldTop = LuaLib.LuaGetTop(this.luaState);
                        if (0 == LuaLib.LuaLLoadBuffer(this.luaState, chunk, fileName))
                        {
                            if (0 == LuaLib.LuaPCall(this.luaState, 0, -1, 0))
                            {
                                return(_PopValues(this.luaState, oldTop));
                            }
                        }

                        _ThrowExceptionFromError(this.luaState, oldTop);
                    }
                }
            } catch (Exception e) {
                Logger <ILuaRuntime> .X(e);
            }

            return(null);
        }
예제 #3
0
        public object[] DoString(byte[] chunk)
        {
            try {
                int oldTop = LuaLib.LuaGetTop(this.luaState);
                if (LuaLib.LuaLLoadBuffer(this.luaState, chunk, "chunkName") == 0)
                {
                    if (0 == LuaLib.LuaPCall(this.luaState, 0, -1, 0))
                    {
                        return(_PopValues(this.luaState, oldTop));
                    }
                }

                _ThrowExceptionFromError(this.luaState, oldTop);
            } catch (Exception e) {
                Logger <ILuaRuntime> .X(e);
            }

            return(null);
        }
예제 #4
0
        private static int _SearcherCallback(LuaState luaState)
        {
            try {
                var fileName = LuaLib.LuaToString(luaState, 1);
                using (var asset = ServiceCenter.GetService <IAssetManager>().Load(fileName + ".txt", AssetType.BYTES)) {
                    var chunk = asset.Cast <byte[]>();
                    if (null == chunk)
                    {
                        throw new Exception("Can't load lua script: " + fileName);
                    }
                    else if (0 != LuaLib.LuaLLoadBuffer(luaState, chunk, fileName))
                    {
                        var err = LuaLib.LuaToString(luaState, -1);
                        throw new Exception(err);
                    }
                }
            } catch (Exception e) {
                Logger <ILuaRuntime> .X(e);
            }

            return(1);
        }