1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
--[[--------------------------------------------------------------------
test_ldump.lua
Test for ldump.lua
This file is part of Yueliang.
Copyright (c) 2006 Kein-Hong Man <khman@users.sf.net>
The COPYRIGHT file describes the conditions
under which this software may be distributed.
See the ChangeLog for more information.
----------------------------------------------------------------------]]
------------------------------------------------------------------------
-- test dump chunkwriter style
------------------------------------------------------------------------
dofile("../lopcodes.lua")
dofile("../ldump.lua")
-- Original typedef:
--int (*lua_Chunkwriter) (lua_State *L, const void* p, size_t sz, void* ud);
local MyWriter, MyBuff = luaU:make_setS()
if not MyWriter then
error("failed to initialize using make_setS")
end
MyWriter("hello, ", MyBuff)
MyWriter("world!", MyBuff)
print(MyBuff.data)
local MyWriter, MyBuff = luaU:make_setF("try.txt")
if not MyWriter then
error("failed to initialize using make_setF")
end
MyWriter("hello, ", MyBuff)
MyWriter("world!", MyBuff)
MyWriter(nil, MyBuff)
------------------------------------------------------------------------
-- test output of a function prototype
-- * data can be copied from a ChunkSpy listing output
------------------------------------------------------------------------
-- local a = 47
-- local b = "hello, world!"
-- print(a, b)
------------------------------------------------------------------------
local F = {}
F.source = "sample.lua"
F.lineDefined = 0
F.lastlinedefined = 0
F.nups = 0
F.numparams = 0
F.is_vararg = 2
F.maxstacksize = 5
F.sizecode = 7
F.code = {}
F.code[0] = { OP = 1, A = 0, Bx = 0 }
F.code[1] = { OP = 1, A = 1, Bx = 1 }
F.code[2] = { OP = 5, A = 2, Bx = 2 }
F.code[3] = { OP = 0, A = 3, B = 0, C = 0 }
F.code[4] = { OP = 0, A = 4, B = 1, C = 0 }
F.code[5] = { OP = 28, A = 2, B = 3, C = 1 }
F.code[6] = { OP = 30, A = 0, B = 1, C = 0 }
F.sizek = 3
F.k = {}
F.k[0] = { value = 47 }
F.k[1] = { value = "hello, world!" }
F.k[2] = { value = "print" }
F.sizep = 0
F.p = {}
F.sizelineinfo = 7
F.lineinfo = {}
F.lineinfo[0] = 1
F.lineinfo[1] = 2
F.lineinfo[2] = 3
F.lineinfo[3] = 3
F.lineinfo[4] = 3
F.lineinfo[5] = 3
F.lineinfo[6] = 3
F.sizelocvars = 2
F.locvars = {}
F.locvars[0] = { varname = "a", startpc = 1, endpc = 6 }
F.locvars[1] = { varname = "b", startpc = 2, endpc = 6 }
F.sizeupvalues = 0
F.upvalues = {}
local L = {}
--[[
local Writer, Buff = luaU:make_setS()
luaU:dump(L, F, Writer, Buff)
for i = 1, string.len(Buff.data) do
io.stdout:write(string.byte(string.sub(Buff.data, i, i)).." ")
end
--]]
local Writer, Buff = luaU:make_setF("try.out")
luaU:dump(L, F, Writer, Buff)
|