public static LuaValueEnum TypeOf(Object val) { if (val == null) { return(LuaValueEnum.LUA_TNIL); } else if (TypeExtension.TypeEqual <bool>(val)) { return(LuaValueEnum.LUA_TBOOLEAN); } else if (TypeExtension.TypeEqual <long>(val) || TypeExtension.TypeEqual <double>(val)) { return(LuaValueEnum.LUA_TNUMBER); } else if (TypeExtension.TypeEqual <string>(val)) { return(LuaValueEnum.LUA_TSTRING); } else if (TypeExtension.TypeEqual <Closure>(val)) { return(LuaValueEnum.LUA_TFUNCTION); } else { return(LuaValueEnum.LUA_TNIL); } }
void setTable(Object t, Object k, Object v) { if (TypeExtension.TypeEqual <LuaTable>(t)) { ((LuaTable)t).Put(k, v); return; } }
LuaValueEnum getTable(Object t, Object k) { if (TypeExtension.TypeEqual <LuaTable>(t)) { Object v = ((LuaTable)t).Get(k); stack.Push(v); return(LuaValue.TypeOf(v)); } throw new Exception(""); }
public void Put(Object key, Object val) { key = floatToInt(key); if (TypeExtension.TypeEqual <long>(key)) { int idx = Convert.ToInt32((long)key); if (idx >= 1) { if (arr == null) { arr = new List <Object>(); } int arrLen = arr.Count; if (idx <= arrLen) { arr[idx - 1] = val; if (idx == arrLen && val == null) { shrinkArray(); } return; } if (idx == arrLen + 1) { if (map != null) { map.Remove(key); } if (val != null) { arr.Add(val); expandArray(); } return; } } } if (val != null) { if (map == null) { map = new Dictionary <object, object>(); } map.Add(key, val); } else { if (map != null) { map.Remove(key); } } }
private Object floatToInt(Object key) { if (TypeExtension.TypeEqual <double>(key)) { double f = (double)key; if (LuaNumber.IsInteger(f)) { return(Convert.ToInt64(f)); } } return(key); }
public Object Get(Object key) { key = floatToInt(key); if (arr != null && TypeExtension.TypeEqual <long>(key)) { int idx = Convert.ToInt32((long)key); if (idx >= 1 && idx <= arr.Count) { return(arr[idx - 1]); } } return(map != null && map.ContainsKey(key) ? map[key] : null); }
public void Call(int nArgs, int nResults) { Object val = stack.Get(-(nArgs + 1)); if (TypeExtension.TypeEqual <Closure>(val)) { Closure c = (Closure)val; Console.WriteLine(""); callLuaClosure(nArgs, nResults, c); } else { throw new Exception("val is not a Closure"); } }
public static bool ToBoolean(Object val) { if (val == null) { return(false); } else if (TypeExtension.TypeEqual <bool>(val)) { return((bool)val); } else { return(true); } }
public double?ToNumberX(int idx) { Object val = stack.Get(idx); if (TypeExtension.TypeEqual <double>(val)) { return((double)val); } else if (TypeExtension.TypeEqual <long>(val)) { return(Convert.ToDouble(((long)val))); } else { return(null); } }
public string ToString(int idx) { Object val = stack.Get(idx); if (TypeExtension.TypeEqual <string>(val)) { return((string)val); } else if (TypeExtension.TypeEqual <long>(val) || TypeExtension.TypeEqual <double>(val)) { return(val.ToString()); } else { return(null); } }
public static double?ToFloat(Object val) { if (TypeExtension.TypeEqual <double>(val)) { return((double)val); } else if (TypeExtension.TypeEqual <long>(val)) { return(Convert.ToDouble(((long)val))); } else if (TypeExtension.TypeEqual <string>(val)) { return(LuaNumber.ParseDouble((string)val)); } else { return(null); } }
public static long?ToInteger(Object val) { if (TypeExtension.TypeEqual <long>(val)) { return((long)val); } else if (TypeExtension.TypeEqual <double>(val)) { double n = (double)val; return(LuaNumber.IsInteger(n) ? (long?)n : null); } else if (TypeExtension.TypeEqual <string>(val)) { return(ToInteger((string)val)); } else { return(null); } }
public static Object Arith(Object a, Object b, ArithOpEnum op) { LongBinaryOperator integerFunc = integerOps[(int)op]; DoubleBinaryOperator floatFunc = floatOps[(int)op]; if (floatFunc == null) { long?x = LuaValue.ToInteger(a); if (x != null) { long?y = LuaValue.ToInteger(b); if (y != null) { return(integerFunc((long)x, (long)y)); } } } else { if (integerFunc != null) { if (TypeExtension.TypeEqual <long>(a) && TypeExtension.TypeEqual <long>(b)) { return(integerFunc((long)a, (long)b)); } } double?x = LuaValue.ToFloat(a); if (x != null) { double?y = LuaValue.ToFloat(b); if (y != null) { return(floatFunc((double)x, (double)y)); } } } return(null); }
public bool IsInteger(int idx) { return(TypeExtension.TypeEqual <int>(stack.Get(idx))); }