static int BufferToString(IntPtr L) { try { object o = CheckObject(L, 1); if (o is byte[]) { byte[] buff = (byte[])o; LuaDLL.lua_pushlstring(L, buff, buff.Length); } else if (o is char[]) { byte[] buff = System.Text.Encoding.UTF8.GetBytes((char[])o); LuaDLL.lua_pushlstring(L, buff, buff.Length); } else if (o is string) { LuaDLL.lua_pushstring(L, (string)o); } else { LuaDLL.luaL_typerror(L, 1, "byte[] or char[]"); } } catch (Exception e) { LuaDLL.toluaL_exception(L, e); } return(1); }
private static int BufferToString(IntPtr L) { try { object obj = ToLua.CheckObject(L, 1); if (obj is byte[]) { byte[] array = (byte[])obj; LuaDLL.lua_pushlstring(L, array, array.Length); } else if (obj is char[]) { byte[] bytes = Encoding.get_UTF8().GetBytes((char[])obj); LuaDLL.lua_pushlstring(L, bytes, bytes.Length); } else if (obj is string) { LuaDLL.lua_pushstring(L, (string)obj); } else { LuaDLL.luaL_typerror(L, 1, "byte[] or char[]", null); } } catch (Exception e) { LuaDLL.toluaL_exception(L, e, null); } return(1); }
static int BufferToString(IntPtr L) { object o = CheckObject(L, 1); if (o is byte[]) { byte[] buff = (byte[])o; LuaDLL.lua_pushlstring(L, buff, buff.Length); } else if (o is char[]) { byte[] buff = (byte[])o; LuaDLL.lua_pushlstring(L, buff, buff.Length); } else { LuaDLL.luaL_typerror(L, 1, "byte[] or char[]"); } return(1); }
public void LuaPushLString(byte[] str, int size) { LuaDLL.lua_pushlstring(L, str, size); }
/*static void PushNull(IntPtr L) * { * LuaDLL.tolua_pushudata(L, 1); * }*/ //PushVarObject public static void Push(IntPtr L, object obj) { if (obj == null) { LuaDLL.lua_pushnil(L); return; } Type t = obj.GetType(); if (t.IsValueType) { if (t == typeof(bool)) { bool b = (bool)obj; LuaDLL.lua_pushboolean(L, b); } else if (t.IsEnum) { Push(L, (System.Enum)obj); } else if (t.IsPrimitive) { double d = LuaMisc.ToDouble(obj); LuaDLL.lua_pushnumber(L, d); } else if (t == typeof(Vector3)) { Push(L, (Vector3)obj); } else if (t == typeof(Quaternion)) { Push(L, (Quaternion)obj); } else if (t == typeof(Vector2)) { Push(L, (Vector2)obj); } else if (t == typeof(Vector4)) { Push(L, (Vector4)obj); } else if (t == typeof(Color)) { Push(L, (Color)obj); } else if (t == typeof(RaycastHit)) { Push(L, (RaycastHit)obj); } else if (t == typeof(Touch)) { Push(L, (Touch)obj); } else if (t == typeof(Ray)) { Push(L, (Ray)obj); } else if (t == typeof(Bounds)) { Push(L, (Bounds)obj); } else if (t == typeof(LayerMask)) { Push(L, (LayerMask)obj); } else { PushValue(L, (ValueType)obj); } } else { if (t.IsArray) { Push(L, (Array)obj); } else if (t == typeof(string)) { LuaDLL.lua_pushstring(L, (string)obj); } else if (t.IsSubclassOf(typeof(LuaBaseRef))) { Push(L, (LuaBaseRef)obj); } else if (t.IsSubclassOf(typeof(UnityEngine.Object))) { Push(L, (UnityEngine.Object)obj); } else if (t.IsSubclassOf(typeof(UnityEngine.TrackedReference))) { Push(L, (UnityEngine.TrackedReference)obj); } else if (t == typeof(LuaByteBuffer)) { LuaByteBuffer lbb = (LuaByteBuffer)obj; LuaDLL.lua_pushlstring(L, lbb.buffer, lbb.buffer.Length); } else if (t.IsSubclassOf(typeof(Delegate))) { Push(L, (Delegate)obj); } else if (obj is System.Collections.IEnumerator) { Push(L, (IEnumerator)obj); } else if (t == typeof(EventObject)) { Push(L, (EventObject)obj); } else if (t == monoType) { Push(L, (Type)obj); } else { PushObject(L, obj); } } }
public static void Push(IntPtr L, LuaByteBuffer bb) { LuaDLL.lua_pushlstring(L, bb.buffer, bb.buffer.Length); }
public static void Push(IntPtr L, object obj) { if (obj == null) { LuaDLL.lua_pushnil(L); return; } Type type = obj.GetType(); if (type.get_IsValueType()) { if (type == typeof(bool)) { bool value = (bool)obj; LuaDLL.lua_pushboolean(L, value); } else if (type.get_IsEnum()) { ToLua.Push(L, (Enum)obj); } else if (type.get_IsPrimitive()) { double number = LuaMisc.ToDouble(obj); LuaDLL.lua_pushnumber(L, number); } else if (type == typeof(Vector3)) { ToLua.Push(L, (Vector3)obj); } else if (type == typeof(Quaternion)) { ToLua.Push(L, (Quaternion)obj); } else if (type == typeof(Vector2)) { ToLua.Push(L, (Vector2)obj); } else if (type == typeof(Vector4)) { ToLua.Push(L, (Vector4)obj); } else if (type == typeof(Color)) { ToLua.Push(L, (Color)obj); } else if (type == typeof(RaycastHit)) { ToLua.Push(L, (RaycastHit)obj); } else if (type == typeof(Touch)) { ToLua.Push(L, (Touch)obj); } else if (type == typeof(Ray)) { ToLua.Push(L, (Ray)obj); } else if (type == typeof(Bounds)) { ToLua.Push(L, (Bounds)obj); } else if (type == typeof(LayerMask)) { ToLua.PushLayerMask(L, (LayerMask)obj); } else { ToLua.PushValue(L, (ValueType)obj); } } else if (type.get_IsArray()) { ToLua.Push(L, (Array)obj); } else if (type == typeof(string)) { LuaDLL.lua_pushstring(L, (string)obj); } else if (type.IsSubclassOf(typeof(LuaBaseRef))) { ToLua.Push(L, (LuaBaseRef)obj); } else if (type.IsSubclassOf(typeof(Object))) { ToLua.Push(L, (Object)obj); } else if (type.IsSubclassOf(typeof(TrackedReference))) { ToLua.Push(L, (TrackedReference)obj); } else if (type == typeof(LuaByteBuffer)) { LuaByteBuffer luaByteBuffer = (LuaByteBuffer)obj; LuaDLL.lua_pushlstring(L, luaByteBuffer.buffer, luaByteBuffer.buffer.Length); } else if (type.IsSubclassOf(typeof(Delegate))) { ToLua.Push(L, (Delegate)obj); } else if (obj is IEnumerator) { ToLua.Push(L, (IEnumerator)obj); } else if (type == typeof(EventObject)) { ToLua.Push(L, (EventObject)obj); } else if (type == ToLua.monoType) { ToLua.Push(L, (Type)obj); } else { ToLua.PushObject(L, obj); } }