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 /win32 | |
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 'win32')
-rw-r--r-- | win32/bin/rclauncher.c | 139 | ||||
-rw-r--r-- | win32/bin/rclauncher.o | bin | 3377 -> 0 bytes | |||
-rw-r--r-- | win32/bin/rclauncher.obj | bin | 4339 -> 0 bytes |
3 files changed, 139 insertions, 0 deletions
diff --git a/win32/bin/rclauncher.c b/win32/bin/rclauncher.c new file mode 100644 index 00000000..60284638 --- /dev/null +++ b/win32/bin/rclauncher.c | |||
@@ -0,0 +1,139 @@ | |||
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/win32/bin/rclauncher.o b/win32/bin/rclauncher.o deleted file mode 100644 index 824d3b6e..00000000 --- a/win32/bin/rclauncher.o +++ /dev/null | |||
Binary files differ | |||
diff --git a/win32/bin/rclauncher.obj b/win32/bin/rclauncher.obj deleted file mode 100644 index 86a32795..00000000 --- a/win32/bin/rclauncher.obj +++ /dev/null | |||
Binary files differ | |||