예제 #1
0
        public void Import(string fileName)
        {
            UniLua.ThreadStatus status = mLuaState.L_DoFile(fileName);
            if (status != UniLua.ThreadStatus.LUA_OK)
            {
                string errmsg = mLuaState.ToString(-1);
                mLuaState.Pop(1);

                System.Text.StringBuilder stsb = new System.Text.StringBuilder();
                stsb.Append("XLuaHolder can not import. \n")
                .AppendFormat("Error: {0} \n", status)
                .AppendFormat("Message: {0} \n", errmsg);
                string message = stsb.ToString();
                throw new Exception(message);
            }
        }
예제 #2
0
        public object Evaluate(string str)
        {
            UniLua.ThreadStatus status = mLuaState.L_DoString(str);
            if (status != UniLua.ThreadStatus.LUA_OK)
            {
                string errmsg = mLuaState.ToString(-1);
                mLuaState.Pop(1);

                System.Text.StringBuilder stsb = new System.Text.StringBuilder();
                stsb.Append("XLuaHolder can not evaluate. \n")
                .AppendFormat("Error: {0} \n", status)
                .AppendFormat("Message: {0} \n", errmsg);
                string message = stsb.ToString();
                throw new Exception(message);
            }

            object result = this.PopRet();

            return(result);
        }
예제 #3
0
        private object SafeInvoke(int funcId, params object[] args)
        {
            mLuaState.PushCSharpFunction(Traceback);
            int traceback = mLuaState.GetTop();

            mLuaState.RawGetI(LuaDef.LUA_REGISTRYINDEX, funcId);
            int numArgs = this.PushArgs(args);

            UniLua.ThreadStatus status = mLuaState.PCall(numArgs, 1, traceback);
            if (status != UniLua.ThreadStatus.LUA_OK)
            {
                throw new Exception(mLuaState.ToString(-1));
            }

            object result = mLuaState.ToObject(-1);

            mLuaState.Pop(1);
            mLuaState.Remove(traceback);
            return(result);
        }