Esempio n. 1
0
 public override object To(Lua.lua_State State, int Index)
 {
     if (Lua.lua_isnumber(State, Index) > 0)
         return (int)Lua.lua_tonumber(State, Index);
     else
         throw new Exception(String.Format("Expected integer (Got {0}).", Lua.lua_typename(State, Index).ToString()));
 }
Esempio n. 2
0
 static Lua.Proto combine(Lua.lua_State L, int n)
 {
     if (n==1)
       return toproto(L,-1);
      else
      {
       int i,pc;
       Lua.Proto f=Lua.luaF_newproto(L);
       Lua.setptvalue2s(L,L.top,f); Lua.incr_top(L);
       f.source=Lua.luaS_newliteral(L,"=(" + PROGNAME + ")");
       f.maxstacksize=1;
       pc=2*n+1;
       f.code = (Instruction[])Lua.luaM_newvector<Instruction>(L, pc);
       f.sizecode=pc;
       f.p = Lua.luaM_newvector<Lua.Proto>(L, n);
       f.sizep=n;
       pc=0;
       for (i=0; i<n; i++)
       {
        f.p[i]=toproto(L,i-n-1);
        f.code[pc++]=(uint)Lua.CREATE_ABx(Lua.OpCode.OP_CLOSURE,0,i);
        f.code[pc++]=(uint)Lua.CREATE_ABC(Lua.OpCode.OP_CALL,0,1,1);
       }
       f.code[pc++]=(uint)Lua.CREATE_ABC(Lua.OpCode.OP_RETURN,0,1,0);
       return f;
      }
 }
Esempio n. 3
0
        /// <summary>
        /// Get the amount of memory used, according to the Lua memory manager
        /// </summary>
        /// <returns>Number of bytes used</returns>
        public static uint GetUsedMem(Lua.lua_State L)
        {
            // Perform a full GC pass first
            Lua.luaC_fullgc(L);

            return L.l_G.totalbytes;
        }
Esempio n. 4
0
 public void AssertLuaResult(Lua.lua_State L, int result)
 {
     if (result != 0)
     {
         Utils.DumpStack(L);
         Assert.Fail(GetLuaError(L));
     }
 }
Esempio n. 5
0
        public string GetLuaError(Lua.lua_State L)
        {
            if (Lua.lua_gettop(L) == 0)
                return "(no error message)";

            var s = Lua.lua_tostring(L, -1);
            if (s == null)
                return "(null error message)";

            return s.ToString();
        }
Esempio n. 6
0
		static int report(Lua.lua_State L, int status)
		{
			if ((status!=0) && !Lua.lua_isnil(L, -1))
			{
				Lua.CharPtr msg = Lua.lua_tostring(L, -1);
				if (msg == null) msg = "(error object is not a string)";
				l_message(progname, msg);
				Lua.lua_pop(L, 1);
			}
			return status;
		}
Esempio n. 7
0
    void Start()
    {
        Lua.lua_State L = Lua.lua_open();
        if (luaL_dostring(L, "return 42, 'butts'"))
        {
            Debug.Log("Success");

            Debug.Log(Lua.lua_tonumber(L, -2));
            Debug.Log(Lua.lua_tostring(L, -1));
        }
        else
        {
            Debug.Log("Failure");
        }
        Lua.lua_close(L);
    }
Esempio n. 8
0
 public static void DumpStack(Lua.lua_State L)
 {
     for (int i = -Lua.lua_gettop(L); i < 0; ++i)
     {
         string s = "?";
         int t = Lua.lua_type(L, i);
         switch (t)
         {
             case Lua.LUA_TSTRING:
                 s = Lua.lua_tostring(L, i).ToString();
                 break;
             case Lua.LUA_TBOOLEAN:
                 s = Lua.lua_toboolean(L, i) != 0 ? "true" : "false";
                 break;
             case Lua.LUA_TNUMBER:
                 s = Lua.lua_tonumber(L, i).ToString();
                 break;
         }
         Debug.WriteLine(string.Format("{0}: {1} {2}", i, Lua.lua_typename(L, t), s));
     }
 }
Esempio n. 9
0
File: lobject.cs Progetto: oathx/Six
			public Node(Lua.LuaTypeValue i_val, TKey i_key)
			{
				this.values = new Node[] { this };
				this.index = 0;
				this.i_val = i_val;
				this.i_key = i_key;
			}
Esempio n. 10
0
File: lobject.cs Progetto: oathx/Six
		internal static bool IsCollectable(Lua.LuaTypeValue o) { return (TType(o) >= LUA_TSTRING); }
Esempio n. 11
0
File: lobject.cs Progetto: oathx/Six
		//#define setsvalue2n	setsvalue
		internal static void SetSValue2N(LuaState L, Lua.LuaTypeValue obj, TString x) { SetSValue(L, obj, x); }
Esempio n. 12
0
File: lobject.cs Progetto: oathx/Six
		//#define setptvalue2s	setptvalue
		internal static void SetPTValue2S(LuaState L, Lua.LuaTypeValue obj, Proto x) { SetPTValue(L, obj, x); }
Esempio n. 13
0
File: lobject.cs Progetto: oathx/Six
		internal static void SetObj(LuaState L, Lua.LuaTypeValue obj1, Lua.LuaTypeValue obj2) {
			obj1.value.Copy(obj2.value);
			obj1.tt = obj2.tt;
			CheckLiveness(G(L), obj1);
		}
Esempio n. 14
0
File: lobject.cs Progetto: oathx/Six
		internal static void SetHValue(LuaState L, Lua.LuaTypeValue obj, Table x) {
			obj.value.gc = x;
			obj.tt = LUA_TTABLE;
			CheckLiveness(G(L), obj);
		}
Esempio n. 15
0
File: lobject.cs Progetto: oathx/Six
		internal static void SetTTHValue(LuaState L, Lua.LuaTypeValue obj, GCObject x) {
			obj.value.gc = x;
			obj.tt = LUA_TTHREAD;
			CheckLiveness(G(L), obj);
		}
Esempio n. 16
0
File: lobject.cs Progetto: oathx/Six
		internal static void SetPValue( Lua.LuaTypeValue obj, object x) {
			obj.value.p = x;
			obj.tt = LUA_TLIGHTUSERDATA;
		}
Esempio n. 17
0
 static bool luaL_dostring(Lua.lua_State L, Lua.CharPtr s)
 {
     return(!(Lua.luaL_loadstring(L, s) == 1 || Lua.lua_pcall(L, 0, Lua.LUA_MULTRET, 0) == 1));
 }
Esempio n. 18
0
File: lobject.cs Progetto: oathx/Six
		internal static void SetBValue(Lua.LuaTypeValue obj, int x) {
			obj.value.b = x;
			obj.tt = LUA_TBOOLEAN;
		}
Esempio n. 19
0
File: lobject.cs Progetto: oathx/Six
		internal static int BValue(Lua.LuaTypeValue o) { return o.value.b; }
Esempio n. 20
0
File: lobject.cs Progetto: oathx/Six
		internal static void SetCLValue(LuaState L, Lua.LuaTypeValue obj, Closure x) {
			obj.value.gc = x;
			obj.tt = LUA_TFUNCTION;
			CheckLiveness(G(L), obj);
		}
Esempio n. 21
0
File: lobject.cs Progetto: oathx/Six
		internal static LuaState THValue(Lua.LuaTypeValue o) { return (LuaState)CheckExp(TTIsThread(o), o.value.gc.th); }
Esempio n. 22
0
File: lobject.cs Progetto: oathx/Six
		internal static void SetPTValue(LuaState L, Lua.LuaTypeValue obj, Proto x) {
			obj.value.gc = x;
			obj.tt = LUATPROTO;
			CheckLiveness(G(L), obj);
		}
Esempio n. 23
0
File: lobject.cs Progetto: oathx/Six
		public static int LIsFalse(Lua.LuaTypeValue o) { return ((TTIsNil(o) || (TTIsBoolean(o) && BValue(o) == 0))) ? 1 : 0; }
Esempio n. 24
0
File: lobject.cs Progetto: oathx/Six
		//#define sethvalue2s	sethvalue
		internal static void SetHValue2S(LuaState L, Lua.LuaTypeValue obj, Table x) { SetHValue(L, obj, x); }
Esempio n. 25
0
File: lobject.cs Progetto: oathx/Six
		internal static void CheckConsistency(Lua.LuaTypeValue obj)
		{
			LuaAssert(!IsCollectable(obj) || (TType(obj) == (obj).value.gc.gch.tt));
		}
Esempio n. 26
0
File: lobject.cs Progetto: oathx/Six
		///* to new object */
		//#define setobj2n	setobj
		internal static void SetObj2N(LuaState L, Lua.LuaTypeValue obj, Lua.LuaTypeValue x) { SetObj(L, obj, x); }
Esempio n. 27
0
File: lobject.cs Progetto: oathx/Six
		internal static void CheckLiveness(GlobalState g, Lua.LuaTypeValue obj)
		{
			LuaAssert(!IsCollectable(obj) ||
			((TType(obj) == obj.value.gc.gch.tt) && !IsDead(g, obj.value.gc)));
		}
Esempio n. 28
0
File: lobject.cs Progetto: oathx/Six
		internal static void SetTType(Lua.LuaTypeValue obj, int tt) { obj.tt = tt; }
Esempio n. 29
0
File: lobject.cs Progetto: oathx/Six
		/* Macros to set values */
		internal static void SetNilValue(Lua.LuaTypeValue obj) {
			obj.tt=LUA_TNIL;
		}
Esempio n. 30
0
File: lobject.cs Progetto: oathx/Six
		public static bool IsLfunction(Lua.LuaTypeValue o) { return ((TType(o) == LUA_TFUNCTION) && (CLValue(o).c.isC==0)); }
Esempio n. 31
0
File: lobject.cs Progetto: oathx/Six
		internal static void SetNValue(Lua.LuaTypeValue obj, LuaNumberType x) {
			obj.value.n = x;
			obj.tt = LUA_TNUMBER;
		}
Esempio n. 32
0
File: lobject.cs Progetto: oathx/Six
		public static int LuaORawEqualObj (Lua.LuaTypeValue t1, Lua.LuaTypeValue t2) {
		  if (TType(t1) != TType(t2)) return 0;
		  else switch (TType(t1)) {
			case LUA_TNIL:
			  return 1;
			case LUA_TNUMBER:
			  return luai_numeq(NValue(t1), NValue(t2)) ? 1 : 0;
			case LUA_TBOOLEAN:
			  return BValue(t1) == BValue(t2) ? 1 : 0;  /* boolean true must be 1....but not in C# !! */
			case LUA_TLIGHTUSERDATA:
				return PValue(t1) == PValue(t2) ? 1 : 0;
			default:
			  LuaAssert(IsCollectable(t1));
			  return GCValue(t1) == GCValue(t2) ? 1 : 0;
		  }
		}
Esempio n. 33
0
        //#endif				/* } */

        //#endif				/* } */


        /*
        ** lua_readline defines how to show a prompt and then read a line from
        ** the standard input.
        ** lua_saveline defines how to "save" a read line in a "history".
        ** lua_freeline defines how to free a line read by lua_readline.
        */
        //#if !defined(lua_readline)	/* { */

        //#if defined(LUA_USE_READLINE)	/* { */

        //#include <readline/readline.h>
        //#include <readline/history.h>
        //#define lua_readline(L,b,p)	((void)L, ((b)=readline(p)) != NULL)
        //#define lua_saveline(L,line)	((void)L, add_history(line))
        //#define lua_freeline(L,b)	((void)L, free(b))

        //#else				/* }{ */

        private static int lua_readline(Lua.lua_State L, Lua.CharPtr b, Lua.CharPtr p)
        {
            /*(void)L,*/ Lua.fputs(p, Lua.stdout); Lua.fflush(Lua.stdout);              /* show prompt */
            return((Lua.fgets(b /*, LUA_MAXINPUT*/, Lua.stdin) != null) ? 1 : 0);
        } /* get line */                                                                //FIXME: no Lua_MAXINPUT