diff options
author | Fabio Mascarenhas <mascarenhas@acm.org> | 2013-04-12 17:04:33 -0300 |
---|---|---|
committer | Fabio Mascarenhas <mascarenhas@acm.org> | 2013-04-12 17:04:33 -0300 |
commit | 8db9fafd0686e1e9ef7092fc9f68e72e45ed26c9 (patch) | |
tree | aea7d2c18520792e4de41acd22d8074a0627aca4 /src | |
parent | 2b7ffae887b922af8224d1990fb0a72980dd363a (diff) | |
download | luarocks-8db9fafd0686e1e9ef7092fc9f68e72e45ed26c9.tar.gz luarocks-8db9fafd0686e1e9ef7092fc9f68e72e45ed26c9.tar.bz2 luarocks-8db9fafd0686e1e9ef7092fc9f68e72e45ed26c9.zip |
fix syntax error on new verbose option
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/rclauncher.c | 139 | ||||
-rw-r--r-- | src/luarocks/fs/win32/tools.lua | 10 |
2 files changed, 5 insertions, 144 deletions
diff --git a/src/bin/rclauncher.c b/src/bin/rclauncher.c deleted file mode 100644 index 60284638..00000000 --- a/src/bin/rclauncher.c +++ /dev/null | |||
@@ -1,139 +0,0 @@ | |||
1 | |||
2 | /* | ||
3 | ** Simple Lua interpreter. | ||
4 | ** This program is used to run a Lua file embedded as a resource. | ||
5 | ** It creates a Lua state, opens all its standard libraries, and run | ||
6 | ** the Lua file in a protected environment just to redirect the error | ||
7 | ** messages to stdout and stderr. | ||
8 | ** | ||
9 | ** $Id: rclauncher.c,v 1.1 2008/06/30 14:29:59 carregal Exp $ | ||
10 | */ | ||
11 | |||
12 | #include <string.h> | ||
13 | #include <stdlib.h> | ||
14 | |||
15 | #include "lua.h" | ||
16 | #include "lauxlib.h" | ||
17 | #include "lualib.h" | ||
18 | #include <windows.h> | ||
19 | #include <io.h> | ||
20 | #include <fcntl.h> | ||
21 | |||
22 | /* | ||
23 | ** Report error message. | ||
24 | ** Assumes that the error message is on top of the stack. | ||
25 | */ | ||
26 | static int report (lua_State *L) { | ||
27 | fprintf (stderr, "lua: fatal error: `%s'\n", lua_tostring (L, -1)); | ||
28 | fflush (stderr); | ||
29 | printf ("Content-type: text/plain\n\nConfiguration fatal error: see error log!\n"); | ||
30 | printf ("%s", lua_tostring(L, -1)); | ||
31 | return 1; | ||
32 | } | ||
33 | |||
34 | static int runlua (lua_State *L, const char *lua_string, int argc, char *argv[]) { | ||
35 | int err_func; | ||
36 | int err; | ||
37 | |||
38 | lua_getglobal(L, "debug"); | ||
39 | lua_pushliteral(L, "traceback"); | ||
40 | lua_gettable(L, -2); | ||
41 | err_func = lua_gettop (L); | ||
42 | err = luaL_loadstring (L, lua_string); | ||
43 | if(!err) { | ||
44 | // fill global arg table | ||
45 | lua_getglobal(L, "arg"); | ||
46 | int i; | ||
47 | for(i = 1; i < argc; i++) | ||
48 | { | ||
49 | lua_pushstring(L, argv[i]); | ||
50 | lua_rawseti(L, -2, i); | ||
51 | } | ||
52 | lua_pop(L, 1); | ||
53 | // fill parameters (in vararg '...') | ||
54 | for(i = 1; i < argc; i++) | ||
55 | lua_pushstring(L, argv[i]); | ||
56 | return lua_pcall (L, argc - 1, LUA_MULTRET, err_func); | ||
57 | } else return err; | ||
58 | } | ||
59 | |||
60 | static DWORD GetModulePath( HINSTANCE hInst, LPTSTR pszBuffer, DWORD dwSize ) | ||
61 | // | ||
62 | // Return the size of the path in bytes. | ||
63 | { | ||
64 | DWORD dwLength = GetModuleFileName( hInst, pszBuffer, dwSize ); | ||
65 | if( dwLength ) | ||
66 | { | ||
67 | while( dwLength && pszBuffer[ dwLength ] != '.' ) | ||
68 | { | ||
69 | dwLength--; | ||
70 | } | ||
71 | |||
72 | if( dwLength ) | ||
73 | pszBuffer[ dwLength ] = '\000'; | ||
74 | } | ||
75 | return dwLength; | ||
76 | } | ||
77 | |||
78 | |||
79 | /* | ||
80 | ** MAIN | ||
81 | */ | ||
82 | int main (int argc, char *argv[]) { | ||
83 | char name[ MAX_PATH ]; | ||
84 | DWORD dwLength; | ||
85 | int size; | ||
86 | luaL_Buffer b; | ||
87 | int i; | ||
88 | #ifdef UNICODE | ||
89 | TCHAR lua_wstring[4098]; | ||
90 | #endif | ||
91 | char lua_string[4098]; | ||
92 | lua_State *L = luaL_newstate(); | ||
93 | (void)argc; /* avoid "unused parameter" warning */ | ||
94 | luaL_openlibs(L); | ||
95 | lua_newtable(L); // create arg table | ||
96 | lua_pushstring(L, argv[0]); // add interpreter to arg table | ||
97 | lua_rawseti(L, -2, -1); | ||
98 | dwLength = GetModulePath( NULL, name, MAX_PATH ); | ||
99 | if(dwLength) { /* Optional bootstrap */ | ||
100 | strcat(name, ".lua"); | ||
101 | lua_pushstring(L, name); // add lua script to arg table | ||
102 | lua_rawseti(L, -2, 0); | ||
103 | lua_setglobal(L,"arg"); // set global arg table | ||
104 | if(!luaL_loadfile (L, name)) { | ||
105 | if(lua_pcall (L, 0, LUA_MULTRET, 0)) { | ||
106 | report (L); | ||
107 | lua_close (L); | ||
108 | return EXIT_FAILURE; | ||
109 | } | ||
110 | } | ||
111 | } | ||
112 | else | ||
113 | { | ||
114 | lua_pushstring(L, argv[0]); // no lua script, so add interpreter again, now as lua script | ||
115 | lua_rawseti(L, -2, 0); | ||
116 | lua_setglobal(L,"arg"); // set global arg table | ||
117 | } | ||
118 | |||
119 | luaL_buffinit(L, &b); | ||
120 | for(i = 1; ; i++) { | ||
121 | #ifdef UNICODE | ||
122 | size = LoadString(GetModuleHandle(NULL), i, lua_wstring, | ||
123 | sizeof(lua_string)/sizeof(TCHAR)); | ||
124 | if(size > 0) wcstombs(lua_string, lua_wstring, size + 1); | ||
125 | #else | ||
126 | size = LoadString(GetModuleHandle(NULL), i, lua_string, | ||
127 | sizeof(lua_string)/sizeof(char)); | ||
128 | #endif | ||
129 | if(size) luaL_addlstring(&b, lua_string, size); else break; | ||
130 | } | ||
131 | luaL_pushresult(&b); | ||
132 | if (runlua (L, lua_tostring(L, -1), argc, argv)) { | ||
133 | report (L); | ||
134 | lua_close (L); | ||
135 | return EXIT_FAILURE; | ||
136 | } | ||
137 | lua_close (L); | ||
138 | return EXIT_SUCCESS; | ||
139 | } | ||
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index eabf125e..c563b137 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua | |||
@@ -9,11 +9,11 @@ local dir = require("luarocks.dir") | |||
9 | local cfg = require("luarocks.cfg") | 9 | local cfg = require("luarocks.cfg") |
10 | 10 | ||
11 | local dir_stack = {} | 11 | local dir_stack = {} |
12 | 12 | ||
13 | local vars = cfg.variables | 13 | local vars = cfg.variables |
14 | 14 | ||
15 | local function pack(...) | 15 | local function pack(...) |
16 | return { n = select("#", ...), ... } | 16 | return { n = select("#", ...), ... } |
17 | end | 17 | end |
18 | 18 | ||
19 | --- Strip the last extension of a filename. | 19 | --- Strip the last extension of a filename. |
@@ -56,12 +56,12 @@ end | |||
56 | -- otherwise. | 56 | -- otherwise. |
57 | function execute_string(cmd) | 57 | function execute_string(cmd) |
58 | cmd = command_at(fs.current_dir(), cmd) | 58 | cmd = command_at(fs.current_dir(), cmd) |
59 | if cfg.verbose then print("Executing: "..tostring(cmd) end | 59 | if cfg.verbose then print("Executing: "..tostring(cmd)) end |
60 | local code = pack(os.execute(cmd)) | 60 | local code = pack(os.execute(cmd)) |
61 | if cfg.verbose then | 61 | if cfg.verbose then |
62 | print("Results: "..tostring(code.n)) | 62 | print("Results: "..tostring(code.n)) |
63 | for i = 1,code.n do | 63 | for i = 1,code.n do |
64 | print(" "..tostring(i).." ("..type(code[i]).."): "..tostring(code[i])) | 64 | print(" "..tostring(i).." ("..type(code[i]).."): "..tostring(code[i])) |
65 | end | 65 | end |
66 | print() | 66 | print() |
67 | end | 67 | end |