public static int luaL_loadbuffer(lua_State L, CharPtr buff, uint size, CharPtr name) { LoadS ls = new LoadS(); ls.s = new CharPtr(buff); ls.size = size; return(lua_load(L, getS, ls, name)); }
public static int LinyeeLLoadBuffer(LinyeeState L, CharPtr buff, uint size, CharPtr name) { LoadS ls = new LoadS(); ls.s = new CharPtr(buff); ls.size = size; return(LinyeeLoad(L, GetS, ls, name)); }
static CharPtr getS(lua_State L, object ud, out uint size) { LoadS ls = (LoadS)ud; //(void)L; //if (ls.size == 0) return null; size = ls.size; ls.size = 0; return(ls.s); }
public static byte[] getS(lua_State L, object ud, ref int size) { LoadS ls = (LoadS)ud; if (ls.size == 0) { return(null); } size = ls.size; ls.size = 0; return(ls.s); }
public static int luaL_loadbuffer(LuaState L, CharPtr buff, uint size, CharPtr name) { LoadS ls = new LoadS(); ls.s = new CharPtr(buff); ls.size = size; return lua_load(L, getS, ls, name); }
public static int LuaLLoadBuffer(LuaState L, CharPtr buff, uint size, CharPtr name) { LoadS ls = new LoadS(); ls.s = new CharPtr(buff); ls.size = size; return LuaLoad(L, GetS, ls, name); }
public static int lua_load(LuaState L, lua_Reader reader, object data, CharPtr chunkname) { ZIO z = new ZIO(); int status; lua_lock(L); if (chunkname == null) { chunkname = "?"; } #if OVERRIDE_LOAD || true //#if false if (data is LoadS) { LoadS d = data as LoadS; if (d.size > 0 && d.s.chars[0] != LUA_SIGNATURE[0]) // if its not binary { Lexer l = new Lexer(); try { //Console.WriteLine(d.s); TokenReader tr = l.Lex(d.s); Parser p = new Parser(tr); Ast.Chunk c = p.Parse(); Visitors.LuaCompatibleOutput lco = new Visitors.LuaCompatibleOutput(); string s = lco.Format(c); d.s = s; d.size = (lu_mem)s.Length; } catch (LuaSourceException ex) { throw ex; } } else { d.s.index = 0; // Why isn't the size equal to the chars.Length? Debug.WriteLine("Binary data: d.size=" + d.size + " d.s.chars.Length=" + d.s.chars.Length); Debug.WriteLine("Equal: " + (d.size == d.s.chars.Length)); //Debug.Assert(d.size == d.s.chars.Length); d.size = (uint)d.s.chars.Length; } } else if (data is LoadF) { LoadF lf = data as LoadF; if (lf.f.ReadByte() != LUA_SIGNATURE[0]) // if its not binary { lf.f.Position = 0; MemoryStream ms = new MemoryStream(); while (lf.f.Position < lf.f.Length) { ms.WriteByte((byte)lf.f.ReadByte()); } ms.Position = 0; // not binary file ms.Position = 0; StringBuilder sb = new StringBuilder(); while (ms.Position < ms.Length) { sb.Append((char)ms.ReadByte()); } try { Lexer l = new Lexer(); TokenReader tr = l.Lex(sb.ToString()); Parser p = new Parser(tr); Ast.Chunk c = p.Parse(); Visitors.LuaCompatibleOutput lco = new Visitors.LuaCompatibleOutput(); string s = lco.Format(c); ms = new MemoryStream(); // TODO: there HAS to be a better way... foreach (char c2 in s) { ms.WriteByte((byte)c2); } ms.Position = 0; lf.f = ms; } catch (LuaSourceException ex) { lua_pushstring(L, ex.GenerateMessage(chunkname)); return(1); //throw ex; } } else { lf.f.Position = 0; // reset the read character } } #endif luaZ_init(L, z, reader, data); status = luaD_protectedparser(L, z, chunkname); lua_unlock(L); if (data is LoadF) { LoadF f = data as LoadF; if (f.f != null) { f.f.Close(); f.f.Dispose(); } } return(status); }
public static int lua_load(LuaState L, lua_Reader reader, object data, CharPtr chunkname) { ZIO z = new ZIO(); int status; lua_lock(L); if (chunkname == null) { chunkname = "?"; } if (data is LoadS) { LoadS d = data as LoadS; if (d.size > 0) { Lexer l = new Lexer(); try { //Console.WriteLine(d.s); TokenReader tr = l.Lex(d.s); Parser p = new Parser(tr); Ast.Chunk c = p.Parse(); Visitors.LuaCompatibleOutput lco = new Visitors.LuaCompatibleOutput(); string s = lco.Format(c); d.s = s; d.size = (lu_mem)s.Length; } catch (LuaSourceException ex) { throw ex; } } } else if (data is LoadF) { LoadF lf = data as LoadF; MemoryStream ms = new MemoryStream(); while (lf.f.Position < lf.f.Length) { ms.WriteByte((byte)lf.f.ReadByte()); } ms.Position = 0; if (ms.ReadByte() != 27) { // not binary file ms.Position = 0; StringBuilder sb = new StringBuilder(); while (ms.Position < ms.Length) { sb.Append((char)ms.ReadByte()); } try { Lexer l = new Lexer(); TokenReader tr = l.Lex(sb.ToString()); Parser p = new Parser(tr); Ast.Chunk c = p.Parse(); Visitors.LuaCompatibleOutput lco = new Visitors.LuaCompatibleOutput(); string s = lco.Format(c); ms = new MemoryStream(); // TODO: there HAS to be a better way... foreach (char c2 in s) { ms.WriteByte((byte)c2); } ms.Position = 0; lf.f = ms; } catch (LuaSourceException ex) { throw ex; } } } luaZ_init(L, z, reader, data); status = luaD_protectedparser(L, z, chunkname); lua_unlock(L); return(status); }