aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorFabio Mascarenhas <mascarenhas@acm.org>2013-04-12 17:05:40 -0300
committerFabio Mascarenhas <mascarenhas@acm.org>2013-04-12 17:05:40 -0300
commit736fa98402202f74160e0bd7cfe7745e34b307ab (patch)
treeb7887f5b88a20c53dd084da88fe23d44215952dc /win32
parente2dea932698d1ded8767476214d41cb2a19641c0 (diff)
downloadluarocks-736fa98402202f74160e0bd7cfe7745e34b307ab.tar.gz
luarocks-736fa98402202f74160e0bd7cfe7745e34b307ab.tar.bz2
luarocks-736fa98402202f74160e0bd7cfe7745e34b307ab.zip
compile rclauncher binary wrapper on windows on every build
Diffstat (limited to 'win32')
-rw-r--r--win32/bin/rclauncher.c174
1 files changed, 87 insertions, 87 deletions
diff --git a/win32/bin/rclauncher.c b/win32/bin/rclauncher.c
index 60284638..77459f46 100644
--- a/win32/bin/rclauncher.c
+++ b/win32/bin/rclauncher.c
@@ -24,55 +24,55 @@
24** Assumes that the error message is on top of the stack. 24** Assumes that the error message is on top of the stack.
25*/ 25*/
26static int report (lua_State *L) { 26static int report (lua_State *L) {
27 fprintf (stderr, "lua: fatal error: `%s'\n", lua_tostring (L, -1)); 27 fprintf (stderr, "lua: fatal error: `%s'\n", lua_tostring (L, -1));
28 fflush (stderr); 28 fflush (stderr);
29 printf ("Content-type: text/plain\n\nConfiguration fatal error: see error log!\n"); 29 printf ("Content-type: text/plain\n\nConfiguration fatal error: see error log!\n");
30 printf ("%s", lua_tostring(L, -1)); 30 printf ("%s", lua_tostring(L, -1));
31 return 1; 31 return 1;
32} 32}
33 33
34static int runlua (lua_State *L, const char *lua_string, int argc, char *argv[]) { 34static int runlua (lua_State *L, const char *lua_string, int argc, char *argv[]) {
35 int err_func; 35 int err_func;
36 int err; 36 int err;
37 37
38 lua_getglobal(L, "debug"); 38 lua_getglobal(L, "debug");
39 lua_pushliteral(L, "traceback"); 39 lua_pushliteral(L, "traceback");
40 lua_gettable(L, -2); 40 lua_gettable(L, -2);
41 err_func = lua_gettop (L); 41 err_func = lua_gettop (L);
42 err = luaL_loadstring (L, lua_string); 42 err = luaL_loadstring (L, lua_string);
43 if(!err) { 43 if(!err) {
44 // fill global arg table 44 int i;
45 lua_getglobal(L, "arg"); 45 // fill global arg table
46 int i; 46 lua_getglobal(L, "arg");
47 for(i = 1; i < argc; i++) 47 for(i = 1; i < argc; i++)
48 { 48 {
49 lua_pushstring(L, argv[i]); 49 lua_pushstring(L, argv[i]);
50 lua_rawseti(L, -2, i); 50 lua_rawseti(L, -2, i);
51 } 51 }
52 lua_pop(L, 1); 52 lua_pop(L, 1);
53 // fill parameters (in vararg '...') 53 // fill parameters (in vararg '...')
54 for(i = 1; i < argc; i++) 54 for(i = 1; i < argc; i++)
55 lua_pushstring(L, argv[i]); 55 lua_pushstring(L, argv[i]);
56 return lua_pcall (L, argc - 1, LUA_MULTRET, err_func); 56 return lua_pcall (L, argc - 1, LUA_MULTRET, err_func);
57 } else return err; 57 } else return err;
58} 58}
59 59
60static DWORD GetModulePath( HINSTANCE hInst, LPTSTR pszBuffer, DWORD dwSize ) 60static DWORD GetModulePath( HINSTANCE hInst, LPTSTR pszBuffer, DWORD dwSize )
61// 61//
62// Return the size of the path in bytes. 62// Return the size of the path in bytes.
63{ 63{
64 DWORD dwLength = GetModuleFileName( hInst, pszBuffer, dwSize ); 64 DWORD dwLength = GetModuleFileName( hInst, pszBuffer, dwSize );
65 if( dwLength ) 65 if( dwLength )
66 { 66 {
67 while( dwLength && pszBuffer[ dwLength ] != '.' ) 67 while( dwLength && pszBuffer[ dwLength ] != '.' )
68 { 68 {
69 dwLength--; 69 dwLength--;
70 } 70 }
71 71
72 if( dwLength ) 72 if( dwLength )
73 pszBuffer[ dwLength ] = '\000'; 73 pszBuffer[ dwLength ] = '\000';
74 } 74 }
75 return dwLength; 75 return dwLength;
76} 76}
77 77
78 78
@@ -80,60 +80,60 @@ static DWORD GetModulePath( HINSTANCE hInst, LPTSTR pszBuffer, DWORD dwSize )
80** MAIN 80** MAIN
81*/ 81*/
82int main (int argc, char *argv[]) { 82int main (int argc, char *argv[]) {
83 char name[ MAX_PATH ]; 83 char name[ MAX_PATH ];
84 DWORD dwLength; 84 DWORD dwLength;
85 int size; 85 int size;
86 luaL_Buffer b; 86 luaL_Buffer b;
87 int i; 87 int i;
88#ifdef UNICODE 88#ifdef UNICODE
89 TCHAR lua_wstring[4098]; 89 TCHAR lua_wstring[4098];
90#endif 90#endif
91 char lua_string[4098]; 91 char lua_string[4098];
92 lua_State *L = luaL_newstate(); 92 lua_State *L = luaL_newstate();
93 (void)argc; /* avoid "unused parameter" warning */ 93 (void)argc; /* avoid "unused parameter" warning */
94 luaL_openlibs(L); 94 luaL_openlibs(L);
95 lua_newtable(L); // create arg table 95 lua_newtable(L); // create arg table
96 lua_pushstring(L, argv[0]); // add interpreter to arg table 96 lua_pushstring(L, argv[0]); // add interpreter to arg table
97 lua_rawseti(L, -2, -1); 97 lua_rawseti(L, -2, -1);
98 dwLength = GetModulePath( NULL, name, MAX_PATH ); 98 dwLength = GetModulePath( NULL, name, MAX_PATH );
99 if(dwLength) { /* Optional bootstrap */ 99 if(dwLength) { /* Optional bootstrap */
100 strcat(name, ".lua"); 100 strcat(name, ".lua");
101 lua_pushstring(L, name); // add lua script to arg table 101 lua_pushstring(L, name); // add lua script to arg table
102 lua_rawseti(L, -2, 0); 102 lua_rawseti(L, -2, 0);
103 lua_setglobal(L,"arg"); // set global arg table 103 lua_setglobal(L,"arg"); // set global arg table
104 if(!luaL_loadfile (L, name)) { 104 if(!luaL_loadfile (L, name)) {
105 if(lua_pcall (L, 0, LUA_MULTRET, 0)) { 105 if(lua_pcall (L, 0, LUA_MULTRET, 0)) {
106 report (L); 106 report (L);
107 lua_close (L); 107 lua_close (L);
108 return EXIT_FAILURE; 108 return EXIT_FAILURE;
109 } 109 }
110 } 110 }
111 } 111 }
112 else 112 else
113 { 113 {
114 lua_pushstring(L, argv[0]); // no lua script, so add interpreter again, now as lua script 114 lua_pushstring(L, argv[0]); // no lua script, so add interpreter again, now as lua script
115 lua_rawseti(L, -2, 0); 115 lua_rawseti(L, -2, 0);
116 lua_setglobal(L,"arg"); // set global arg table 116 lua_setglobal(L,"arg"); // set global arg table
117 } 117 }
118 118
119 luaL_buffinit(L, &b); 119 luaL_buffinit(L, &b);
120 for(i = 1; ; i++) { 120 for(i = 1; ; i++) {
121#ifdef UNICODE 121#ifdef UNICODE
122 size = LoadString(GetModuleHandle(NULL), i, lua_wstring, 122 size = LoadString(GetModuleHandle(NULL), i, lua_wstring,
123 sizeof(lua_string)/sizeof(TCHAR)); 123 sizeof(lua_string)/sizeof(TCHAR));
124 if(size > 0) wcstombs(lua_string, lua_wstring, size + 1); 124 if(size > 0) wcstombs(lua_string, lua_wstring, size + 1);
125#else 125#else
126 size = LoadString(GetModuleHandle(NULL), i, lua_string, 126 size = LoadString(GetModuleHandle(NULL), i, lua_string,
127 sizeof(lua_string)/sizeof(char)); 127 sizeof(lua_string)/sizeof(char));
128#endif 128#endif
129 if(size) luaL_addlstring(&b, lua_string, size); else break; 129 if(size) luaL_addlstring(&b, lua_string, size); else break;
130 } 130 }
131 luaL_pushresult(&b); 131 luaL_pushresult(&b);
132 if (runlua (L, lua_tostring(L, -1), argc, argv)) { 132 if (runlua (L, lua_tostring(L, -1), argc, argv)) {
133 report (L); 133 report (L);
134 lua_close (L); 134 lua_close (L);
135 return EXIT_FAILURE; 135 return EXIT_FAILURE;
136 } 136 }
137 lua_close (L); 137 lua_close (L);
138 return EXIT_SUCCESS; 138 return EXIT_SUCCESS;
139} 139}