public Dictionary <string, object> DoString(string str, string name = "[string]") { if (!thn_compile(str, name, out IntPtr buf, out int sz)) { var err = thn_geterror(); var errstring = UnsafeHelpers.PtrToStringUTF8(err); thn_free(err); throw new Exception(errstring); } var compiled = new byte[sz]; Marshal.Copy(buf, compiled, 0, sz); thn_free(buf); using (var stream = new MemoryStream(compiled)) { LuaPrototype p; if (!Undump.Load(stream, out p)) { throw new Exception("Undump failed"); } var runtime = new LuaBinaryRuntime(p); runtime.Env = Env; runtime.Run(); return(runtime.Globals); } }
public Dictionary <string, object> DoFile(string filename) { using (var stream = File.OpenRead(filename)) { LuaPrototype p; if (Undump.Load(stream, out p)) { var runtime = new LuaBinaryRuntime(p); runtime.Env = Env; runtime.Run(); return(runtime.Globals); } else { stream.Position = 0; return(DoTextFile(stream)); } } }