public void TestDump() { LuaState L = null; using (L = new LuaState()) { String chunk = @" a = 'Lua' b = ' rocks' c=a..b return c..'!!' "; Byte[] chunkBytes = Encoding.ASCII.GetBytes(chunk); int curr = 0; LuaReader loadChunk = (l, ud) => { Byte[] res = null; if (curr < chunkBytes.Length) { int c = Math.Min(chunkBytes.Length, chunkBytes.Length - curr); res = new Byte[c]; Array.Copy(chunkBytes, curr, res, 0, c); curr += c; } return res; }; var st = L.Load(loadChunk, null, "main", null); Assert.Equal(LuaStatus.OK, st); List<Byte[]> dump = new List<byte[]>(); var r = L.Dump((l, b, ud) => { dump.Add(b); return 0; }, null, 0); Assert.Equal(0, r); Byte[] dumpBytes = dump.SelectMany(d => d).ToArray(); Assert.Equal(199, dumpBytes.Length); // Remove the function L.Pop(1); Assert.Equal(0, L.GetTop()); // Reload chunk compiled chunkBytes = dumpBytes; curr = 0; st = L.Load(loadChunk, null, "main", "b"); Assert.Equal(LuaStatus.OK, st); st = L.PCall(0, 1, 0); Assert.Equal(LuaStatus.OK, st); Assert.Equal("Lua rocks!!", L.ToString(-1)); } }