diff options
Diffstat (limited to '')
-rw-r--r-- | LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/luac.lua | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/luac.lua b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/luac.lua new file mode 100644 index 0000000..80cc4a5 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/luac.lua | |||
@@ -0,0 +1,71 @@ | |||
1 | --[[-------------------------------------------------------------------- | ||
2 | |||
3 | luac.lua | ||
4 | Primitive luac in Lua | ||
5 | This file is part of Yueliang. | ||
6 | |||
7 | Copyright (c) 2005 Kein-Hong Man <khman@users.sf.net> | ||
8 | The COPYRIGHT file describes the conditions | ||
9 | under which this software may be distributed. | ||
10 | |||
11 | See the ChangeLog for more information. | ||
12 | |||
13 | ----------------------------------------------------------------------]] | ||
14 | |||
15 | --[[-------------------------------------------------------------------- | ||
16 | -- Notes: | ||
17 | -- * based on luac.lua in the test directory of the 5.0.3 distribution | ||
18 | -- * usage: lua luac.lua file.lua | ||
19 | ----------------------------------------------------------------------]] | ||
20 | |||
21 | ------------------------------------------------------------------------ | ||
22 | -- load and initialize the required modules | ||
23 | ------------------------------------------------------------------------ | ||
24 | require("lzio.lua") | ||
25 | require("llex.lua") | ||
26 | require("lopcodes.lua") | ||
27 | require("ldump.lua") | ||
28 | require("lcode.lua") | ||
29 | require("lparser.lua") | ||
30 | |||
31 | luaX:init() -- required by llex | ||
32 | local LuaState = {} -- dummy, not actually used, but retained since | ||
33 | -- the intention is to complete a straight port | ||
34 | |||
35 | ------------------------------------------------------------------------ | ||
36 | -- interfacing to yueliang | ||
37 | ------------------------------------------------------------------------ | ||
38 | |||
39 | -- currently asserts are enabled because the codebase hasn't been tested | ||
40 | -- much (if you don't want asserts, just comment them out) | ||
41 | function lua_assert(test) | ||
42 | if not test then error("assertion failed!") end | ||
43 | end | ||
44 | |||
45 | function yloadfile(filename) | ||
46 | -- luaZ:make_getF returns a file chunk reader | ||
47 | -- luaZ:init returns a zio input stream | ||
48 | local zio = luaZ:init(luaZ:make_getF(filename), nil, "@"..filename) | ||
49 | if not zio then return end | ||
50 | -- luaY:parser parses the input stream | ||
51 | -- func is the function prototype in tabular form; in C, func can | ||
52 | -- now be used directly by the VM, this can't be done in Lua | ||
53 | local func = luaY:parser(LuaState, zio, nil) | ||
54 | -- luaU:make_setS returns a string chunk writer | ||
55 | local writer, buff = luaU:make_setS() | ||
56 | -- luaU:dump builds a binary chunk | ||
57 | luaU:dump(LuaState, func, writer, buff) | ||
58 | -- a string.dump equivalent in returned | ||
59 | return buff.data | ||
60 | end | ||
61 | |||
62 | ------------------------------------------------------------------------ | ||
63 | -- command line interface | ||
64 | ------------------------------------------------------------------------ | ||
65 | |||
66 | assert(arg[1] ~= nil and arg[2] == nil, "usage: lua luac.lua file.lua") | ||
67 | local f = assert(io.open("luac.out","wb")) | ||
68 | f:write(assert(yloadfile(arg[1]))) | ||
69 | io.close(f) | ||
70 | |||
71 | --end | ||