private static void comparison(lua_Type tag_less, lua_Type tag_equal, lua_Type tag_great, CharPtr op) { Object_ l = top.get(-2); Object_ r = top.get(-1); int result; if (tag(l) == lua_Type.LUA_T_NUMBER && tag(r) == lua_Type.LUA_T_NUMBER) { result = (nvalue(l) < nvalue(r)) ? -1 : (nvalue(l) == nvalue(r)) ? 0 : 1; } else if (tostring(l) || tostring(r)) { lua_pushstring(op); do_call(luaI_fallBacks[FB_ORDER].function, ObjectRef.minus(top, stack) - 3, 1, ObjectRef.minus(top, stack) - 3); return; } else { result = strcmp(svalue(l), svalue(r)); } top.dec(); nvalue(top.get(-1), 1); tag(top.get(-1), (result < 0) ? tag_less : ((result == 0) ? tag_equal : tag_great)); }
private static void DumpFilesToObjects(string path) { string[] lines = File.ReadAllLines(path); for (int i = 0; i < lines.Length; i++) { string[] tmpString = lines[i].Split('\t'); Object_ tmp = new Object_(); tmp.Id = Convert.ToUInt32(tmpString[1]); tmp.Name = tmpString[2]; tmp.OtherName = tmpString[3]; tmp.Type = 1; tmp.Type1 = 1; tmp.Speed = Convert.ToSingle(tmpString[50]); tmp.Level = Convert.ToByte(tmpString[57]); tmp.Hp = Convert.ToUInt32(tmpString[59]); tmp.InvSize = 0; tmp.PhyDef = Convert.ToUInt16(tmpString[71]); tmp.MagDef = Convert.ToUInt16(tmpString[72]); tmp.HitRatio = Convert.ToByte(tmpString[75]); tmp.ParryRatio = Convert.ToByte(tmpString[77]); tmp.Exp = Convert.ToUInt64(tmpString[79]); tmp.Skill1 = Convert.ToUInt32(tmpString[83]); tmp.Skill2 = Convert.ToUInt32(tmpString[85]); tmp.Skill3 = Convert.ToUInt32(tmpString[86]); tmp.Skill4 = Convert.ToUInt32(tmpString[87]); tmp.Skill5 = Convert.ToUInt32(tmpString[88]); tmp.Skill6 = Convert.ToUInt32(tmpString[89]); tmp.Skill7 = Convert.ToUInt32(tmpString[90]); tmp.Skill8 = Convert.ToUInt32(tmpString[91]); tmp.Skill9 = Convert.ToUInt32(tmpString[92]); Objects.Add(tmp); } }
/* ** If the hash node is present, return its pointer, otherwise create a new ** node for the given reference and also return its pointer. ** On error, return NULL. */ public static Object_ lua_hashdefine(Hash t, Object_ @ref) { int h; NodeRef n; h = head(t, @ref); if (h < 0) { return(null); } n = present(t, @ref, h); if (n == null) { n = NodeRef.assign(new_Node()); //(Node) new_("Node"); if (n == null) { lua_error("not enough memory"); return(null); } n.get()[email protected](@ref); tag(n.get().val, Type.T_NIL); n.get().next = NodeRef.assign(list(t, h)); /* link node to head of list */ list(t, h, n.get()); } return(n.get().val); }
private static int do_protectedmain() { BytePtr code = null; int status; StkId oldCBase = CBase; jmp_buf myErrorJmp = new jmp_buf(); jmp_buf oldErr = errorJmp; errorJmp = myErrorJmp; try //if (setjmp(myErrorJmp) == 0) { Object_ f = new Object_(); lua_parse(ref code); tag(f, lua_Type.LUA_T_FUNCTION); bvalue(f, code); do_call(f, CBase, 0, CBase); status = 0; } catch (LongjmpException) { //else { status = 1; } if (code != null) { luaI_free_BytePtr(ref code); } errorJmp = oldErr; CBase = oldCBase; top = new ObjectRef(stack, CBase); return(status); }
/* ** Call a function (C or Lua). The parameters must be on the stack, ** between [stack+base,top). When returns, the results are on the stack, ** between [stack+whereRes,top). The number of results is nResults, unless ** nResults=MULT_RET. */ private static void do_call(Object_ func, StkId @base, int nResults, StkId whereRes) { StkId firstResult; if (tag(func) == lua_Type.LUA_T_CFUNCTION) { firstResult = callC(fvalue(func), @base); } else if (tag(func) == lua_Type.LUA_T_FUNCTION) { firstResult = lua_execute(bvalue(func), @base); } else { /* func is not a function */ call_funcFB(func, @base, nResults, whereRes); return; } /* adjust the number of results */ if (nResults != MULT_RET && ObjectRef.minus(top, new ObjectRef(stack, firstResult)) != nResults) { adjust_top(firstResult + nResults); } /* move results to the given position */ if (firstResult != whereRes) { int i; nResults = ObjectRef.minus(top, new ObjectRef(stack, firstResult)); /* actual number of results */ for (i = 0; i < nResults; i++) { stack[whereRes + i].set(stack[firstResult + i]); } top.add(-(firstResult - whereRes)); } }
public static void tag(Object_ o, Type t) { // if (t == Type.T_NUMBER) // { // Console.WriteLine("=============="); // } o.tag = t; }
//#define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s))) public static Object_[] newvector_Object(int maxstack) { Object_[] stack = new Object_[maxstack]; for (int i = 0; i < stack.Length; ++i) { stack[i] = new Object_(); } return(stack); }
//#endif private static Object_[] _initstack() { Object_[] stack = new Object_[MAXSTACK]; for (int i = 0; i < stack.Length; ++i) { stack[i] = new Object_(); } stack[0].tag = Type.T_MARK; return(stack); }
/* ** Mark an object if it is a string or a unmarked array. */ public static void lua_markobject(Object_ o) { if (tag(o) == Type.T_STRING) { markstring(svalue(o), (char)1); } else if (tag(o) == Type.T_ARRAY) { lua_hashmark(avalue(o)); } }
/* ** Mark an object if it is a string or a unmarked array. */ public static void lua_markobject(Object_ o) { if (tag(o) == Type.T_STRING) { lua_markstring(svalue(o), (char)1); //FIXME:??? } else if (tag(o) == Type.T_ARRAY && markarray(avalue(o)) == 0) { lua_hashmark(avalue(o)); } }
/* ** Mark an object if it is a string or a unmarked array. */ public static void lua_markobject(Object_ o) { if (tag(o) == lua_Type.LUA_T_STRING && (char)0 == tsvalue(o).marked) { tsvalue(o).marked = (char)1; } else if (tag(o) == lua_Type.LUA_T_ARRAY) { lua_hashmark(avalue(o)); } }
/* ** Push an object to stack. */ public static int lua_pushobject(Object_ o) { if ((top.minus(stack)) >= MAXSTACK - 1) { lua_error("stack overflow"); return(1); } top.get().set(o); top.inc(); return(0); }
/* ** Function to store indexed based on values at the top */ private static void storesubscript() { if (tag(top.get(-3)) != lua_Type.LUA_T_ARRAY) { do_call(luaI_fallBacks[FB_SETTABLE].function, ObjectRef.minus(top, stack) - 3, 0, ObjectRef.minus(top, stack) - 3); } else { Object_ h = lua_hashdefine(avalue(top.get(-3)), top.get(-2)); h.set(top.get(-1)); top.add(-3); } }
/* ** Call the fallback for invalid functions (see do_call) */ private static void call_funcFB(Object_ func, StkId @base, int nResults, StkId whereRes) { StkId i; /* open space for first parameter (func) */ for (i = ObjectRef.minus(top, stack); i > @base; i--) { stack[i] = stack[i - 1]; } top.inc(); stack[@base].set(func); do_call(luaI_fallBacks[FB_FUNCTION].function, @base, nResults, whereRes); }
/* ** If the hash node is present, return its pointer, otherwise return ** null. */ public static Object_ lua_hashget(Hash t, Object_ @ref) { Word h = present(t, @ref); if (tag(ref_(node(t, h))) != lua_Type.LUA_T_NIL) { return(val_(node(t, h))); } else { return(null); } }
public static Object[] FromTSObject(dynamic[] tsArray) { if (tsArray is null) { return(null); } var list = new System.Collections.Generic.List <Object>(); foreach (var tsItem in tsArray) { list.Add(Object_.FromTSObject(tsItem)); } return(list.ToArray()); }
public static dynamic GetTSObject(Object[] dynArray) { if (dynArray is null) { return(null); } var list = new System.Collections.Generic.List <dynamic>(); foreach (var dynItem in dynArray) { list.Add(Object_.GetTSObject(dynItem)); } return(list.ToArray()); }
private static Word present(Hash t, Object_ @ref) { Word h = hashindex(t, @ref); while (tag(ref_(node(t, h))) != lua_Type.LUA_T_NIL) { if (0 != lua_equalObj(@ref, ref_(node(t, h)))) { return(h); } h = (Word)((h + 1) % nhash(t)); } return(h); }
/* ** Given an object handle, return its number value. On error, return 0.0. */ public static real lua_getnumber(Object_ @object) { if (@object == null || tag(@object) == Type.T_NIL) { return(0.0f); } if (tonumber(@object)) { return(0.0f); } else { return(nvalue(@object)); } }
/* ** Given an object handle, return its user data. On error, return NULL. */ public static object lua_getuserdata(Object_ @object) { if (@object == null) { return(null); } if (tag(@object) != Type.T_USERDATA) { return(null); } else { return(uvalue(@object)); } }
/* ** Given an object handle, return its cfuntion pointer. On error, return NULL. */ public static lua_CFunction lua_getcfunction(Object_ @object) { if (@object == null) { return(null); } if (tag(@object) != Type.T_CFUNCTION) { return(null); } else { return(fvalue(@object)); } }
/* ** Given an object handle, return a copy of its string. On error, return NULL. */ public static CharPtr lua_copystring(Object_ @object) { if (@object == null || tag(@object) == Type.T_NIL) { return(null); } if (tostring(@object)) { return(null); } else { return(strdup(svalue(@object))); } }
//#define growvector(old,n,s) ((s *)luaI_realloc(old,(n)*sizeof(s))) public static Object_[] growvector_Object(Object_[] stack, int maxstack) { Object_[] oldarr = stack; stack = new Object_[maxstack]; for (int k = 0; k < stack.Length; ++k) { if (k < oldarr.Length) { stack[k] = oldarr[k]; } else { stack[k] = new Object_(); } } return(stack); }
private static void call_fallbacks() { Hash curr_array; Object_ t = new Object_(); tag(t, lua_Type.LUA_T_ARRAY); for (curr_array = listhead; curr_array != null; curr_array = curr_array.next) { if (markarray(curr_array) != 1) { avalue(t, curr_array); luaI_gcFB(t); } } tag(t, lua_Type.LUA_T_NIL); luaI_gcFB(t); /* end of list */ }
/* ** Convert, if possible, to a number tag. ** Return 0 in success or not 0 on error. */ internal static int lua_tonumber(Object_ obj) { CharPtr ptr = null; if (tag(obj) != Type.T_STRING) { lua_reportbug("unexpected type at conversion to number"); return(1); } nvalue(obj, (float)strtod(svalue(obj), ref ptr)); if (ptr[0] != '\0') { lua_reportbug("string to number convertion failed"); return(2); } tag(obj, Type.T_NUMBER); return(0); }
public void setRef(Object_ o) { bool found = false; for (int i = 0; i < obj.Length; ++i) { if (o == obj[i]) { this.index = i; found = true; break; } } if (found == false) { throw new Exception("objs not same"); } }
/* ** Given an object handle and an index, return its indexed object. ** On error, return NULL. */ public static Object_ lua_getindexed(Object_ @object, float index) { if (@object == null) { return(null); } if (tag(@object) != Type.T_ARRAY) { return(null); } else { Object_ @ref = new Object_(); tag(@ref, Type.T_NUMBER); nvalue(@ref, index); return(lua_hashdefine(avalue(@object), @ref)); } }
/* ** Given an object handle and a field name, return its field object. ** On error, return NULL. */ public static Object lua_getfield(Object_ @object, CharPtr field) { if (@object == null) { return(null); } if (tag(@object) != Type.T_ARRAY) { return(null); } else { Object_ @ref = new Object_(); tag(@ref, Type.T_STRING); svalue(@ref, lua_createstring(lua_strdup(field))); return(lua_hashdefine(avalue(@object), @ref)); } }
/* ** Execute the given function. Return 0 on success or 1 on error. */ public static int lua_call(CharPtr functionname, int nparam) { // static Byte startcode[] = {CALLFUNC, HALT}; int i; Object_ func = new Object_(); func.set(s_object(lua_findsymbol(functionname))); //FIXME:???copy??? if (tag(func) != Type.T_FUNCTION) { return(1); } for (i = 1; i <= nparam; i++) { top.get(-i + 2).set(top.get(-i)); } top.add(2); tag(top.get(-nparam - 1), Type.T_MARK); top.get(-nparam - 2).set(func); return(lua_execute(new BytePtr(lua_call_startcode, 0))); }
private static NodeRef present(Hash t, Object_ @ref, int h) { NodeRef n = null, p = null; if (tag(@ref) == Type.T_NUMBER) { for (p = null, n = list(t, h); n != null; p = n, n = NodeRef.assign(n.get().next)) { if (ref_tag(n.get()) == Type.T_NUMBER && nvalue(@ref) == ref_nvalue(n.get())) { break; } } } else if (tag(@ref) == Type.T_STRING) { for (p = null, n = list(t, h); n != null; p = n, n = NodeRef.assign(n.get().next)) { // if (ref_tag(n.get()) == Type.T_STRING) // { // Console.WriteLine("=========================" + svalue(@ref).ToString() + ", " + ref_svalue(n.get())); // } if (ref_tag(n.get()) == Type.T_STRING && streq(svalue(@ref), ref_svalue(n.get()))) { // Console.WriteLine("========================="); break; } } } if (n == null) /* name not present */ { return(null); } #if false if (p != null) /* name present but not first */ { p.next = n.next; /* move-to-front self-organization */ n.next = list(t, h); list(t, h, n); } #endif return(n); }