revert PtrToStringAnsi
add fallback in tostring
@@ -113,7 +113,7 @@ namespace SLua
public static string lua_typenamestr(IntPtr luaState, LuaTypes type)
{
IntPtr p = lua_typename(luaState, (int)type);
- return Marshal.PtrToStringAuto(p);
+ return Marshal.PtrToStringAnsi(p);
}
public static string luaL_typename(IntPtr luaState, int stackPos)
{
@@ -533,12 +533,19 @@ namespace SLua
int strlen;
IntPtr str = luaS_tolstring32(luaState, index, out strlen); // fix il2cpp 64 bit
-
- if (str != IntPtr.Zero)
+ string s = null;
+ if (strlen > 0 && str != IntPtr.Zero)
+ {
+ s = Marshal.PtrToStringAnsi(str, strlen);
+ // fallback method
+ if(s == null)
{
- return Marshal.PtrToStringAuto (str);
+ byte[] b = new byte[strlen];
+ Marshal.Copy(str, b, 0, strlen);
+ s = System.Text.Encoding.Default.GetString(b);
}
- return null;
+ }
+ return (s == null) ? string.Empty : s;
}
public static byte[] lua_tobytes(IntPtr luaState, int index)
