From 8db9fafd0686e1e9ef7092fc9f68e72e45ed26c9 Mon Sep 17 00:00:00 2001 From: Fabio Mascarenhas Date: Fri, 12 Apr 2013 17:04:33 -0300 Subject: fix syntax error on new verbose option --- src/bin/rclauncher.c | 139 ---------------------------------------- src/luarocks/fs/win32/tools.lua | 10 +-- win32/bin/rclauncher.c | 139 ++++++++++++++++++++++++++++++++++++++++ win32/bin/rclauncher.o | Bin 3377 -> 0 bytes win32/bin/rclauncher.obj | Bin 4339 -> 0 bytes 5 files changed, 144 insertions(+), 144 deletions(-) delete mode 100644 src/bin/rclauncher.c create mode 100644 win32/bin/rclauncher.c delete mode 100644 win32/bin/rclauncher.o delete mode 100644 win32/bin/rclauncher.obj 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 @@ - -/* -** Simple Lua interpreter. -** This program is used to run a Lua file embedded as a resource. -** It creates a Lua state, opens all its standard libraries, and run -** the Lua file in a protected environment just to redirect the error -** messages to stdout and stderr. -** -** $Id: rclauncher.c,v 1.1 2008/06/30 14:29:59 carregal Exp $ -*/ - -#include -#include - -#include "lua.h" -#include "lauxlib.h" -#include "lualib.h" -#include -#include -#include - -/* -** Report error message. -** Assumes that the error message is on top of the stack. -*/ -static int report (lua_State *L) { - fprintf (stderr, "lua: fatal error: `%s'\n", lua_tostring (L, -1)); - fflush (stderr); - printf ("Content-type: text/plain\n\nConfiguration fatal error: see error log!\n"); - printf ("%s", lua_tostring(L, -1)); - return 1; -} - -static int runlua (lua_State *L, const char *lua_string, int argc, char *argv[]) { - int err_func; - int err; - - lua_getglobal(L, "debug"); - lua_pushliteral(L, "traceback"); - lua_gettable(L, -2); - err_func = lua_gettop (L); - err = luaL_loadstring (L, lua_string); - if(!err) { - // fill global arg table - lua_getglobal(L, "arg"); - int i; - for(i = 1; i < argc; i++) - { - lua_pushstring(L, argv[i]); - lua_rawseti(L, -2, i); - } - lua_pop(L, 1); - // fill parameters (in vararg '...') - for(i = 1; i < argc; i++) - lua_pushstring(L, argv[i]); - return lua_pcall (L, argc - 1, LUA_MULTRET, err_func); - } else return err; -} - -static DWORD GetModulePath( HINSTANCE hInst, LPTSTR pszBuffer, DWORD dwSize ) -// -// Return the size of the path in bytes. -{ - DWORD dwLength = GetModuleFileName( hInst, pszBuffer, dwSize ); - if( dwLength ) - { - while( dwLength && pszBuffer[ dwLength ] != '.' ) - { - dwLength--; - } - - if( dwLength ) - pszBuffer[ dwLength ] = '\000'; - } - return dwLength; -} - - -/* -** MAIN -*/ -int main (int argc, char *argv[]) { - char name[ MAX_PATH ]; - DWORD dwLength; - int size; - luaL_Buffer b; - int i; -#ifdef UNICODE - TCHAR lua_wstring[4098]; -#endif - char lua_string[4098]; - lua_State *L = luaL_newstate(); - (void)argc; /* avoid "unused parameter" warning */ - luaL_openlibs(L); - lua_newtable(L); // create arg table - lua_pushstring(L, argv[0]); // add interpreter to arg table - lua_rawseti(L, -2, -1); - dwLength = GetModulePath( NULL, name, MAX_PATH ); - if(dwLength) { /* Optional bootstrap */ - strcat(name, ".lua"); - lua_pushstring(L, name); // add lua script to arg table - lua_rawseti(L, -2, 0); - lua_setglobal(L,"arg"); // set global arg table - if(!luaL_loadfile (L, name)) { - if(lua_pcall (L, 0, LUA_MULTRET, 0)) { - report (L); - lua_close (L); - return EXIT_FAILURE; - } - } - } - else - { - lua_pushstring(L, argv[0]); // no lua script, so add interpreter again, now as lua script - lua_rawseti(L, -2, 0); - lua_setglobal(L,"arg"); // set global arg table - } - - luaL_buffinit(L, &b); - for(i = 1; ; i++) { -#ifdef UNICODE - size = LoadString(GetModuleHandle(NULL), i, lua_wstring, - sizeof(lua_string)/sizeof(TCHAR)); - if(size > 0) wcstombs(lua_string, lua_wstring, size + 1); -#else - size = LoadString(GetModuleHandle(NULL), i, lua_string, - sizeof(lua_string)/sizeof(char)); -#endif - if(size) luaL_addlstring(&b, lua_string, size); else break; - } - luaL_pushresult(&b); - if (runlua (L, lua_tostring(L, -1), argc, argv)) { - report (L); - lua_close (L); - return EXIT_FAILURE; - } - lua_close (L); - return EXIT_SUCCESS; -} 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") local cfg = require("luarocks.cfg") local dir_stack = {} - + local vars = cfg.variables -local function pack(...) - return { n = select("#", ...), ... } +local function pack(...) + return { n = select("#", ...), ... } end --- Strip the last extension of a filename. @@ -56,12 +56,12 @@ end -- otherwise. function execute_string(cmd) cmd = command_at(fs.current_dir(), cmd) - if cfg.verbose then print("Executing: "..tostring(cmd) end + if cfg.verbose then print("Executing: "..tostring(cmd)) end local code = pack(os.execute(cmd)) if cfg.verbose then print("Results: "..tostring(code.n)) for i = 1,code.n do - print(" "..tostring(i).." ("..type(code[i]).."): "..tostring(code[i])) + print(" "..tostring(i).." ("..type(code[i]).."): "..tostring(code[i])) end print() end 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 @@ + +/* +** Simple Lua interpreter. +** This program is used to run a Lua file embedded as a resource. +** It creates a Lua state, opens all its standard libraries, and run +** the Lua file in a protected environment just to redirect the error +** messages to stdout and stderr. +** +** $Id: rclauncher.c,v 1.1 2008/06/30 14:29:59 carregal Exp $ +*/ + +#include +#include + +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +#include +#include +#include + +/* +** Report error message. +** Assumes that the error message is on top of the stack. +*/ +static int report (lua_State *L) { + fprintf (stderr, "lua: fatal error: `%s'\n", lua_tostring (L, -1)); + fflush (stderr); + printf ("Content-type: text/plain\n\nConfiguration fatal error: see error log!\n"); + printf ("%s", lua_tostring(L, -1)); + return 1; +} + +static int runlua (lua_State *L, const char *lua_string, int argc, char *argv[]) { + int err_func; + int err; + + lua_getglobal(L, "debug"); + lua_pushliteral(L, "traceback"); + lua_gettable(L, -2); + err_func = lua_gettop (L); + err = luaL_loadstring (L, lua_string); + if(!err) { + // fill global arg table + lua_getglobal(L, "arg"); + int i; + for(i = 1; i < argc; i++) + { + lua_pushstring(L, argv[i]); + lua_rawseti(L, -2, i); + } + lua_pop(L, 1); + // fill parameters (in vararg '...') + for(i = 1; i < argc; i++) + lua_pushstring(L, argv[i]); + return lua_pcall (L, argc - 1, LUA_MULTRET, err_func); + } else return err; +} + +static DWORD GetModulePath( HINSTANCE hInst, LPTSTR pszBuffer, DWORD dwSize ) +// +// Return the size of the path in bytes. +{ + DWORD dwLength = GetModuleFileName( hInst, pszBuffer, dwSize ); + if( dwLength ) + { + while( dwLength && pszBuffer[ dwLength ] != '.' ) + { + dwLength--; + } + + if( dwLength ) + pszBuffer[ dwLength ] = '\000'; + } + return dwLength; +} + + +/* +** MAIN +*/ +int main (int argc, char *argv[]) { + char name[ MAX_PATH ]; + DWORD dwLength; + int size; + luaL_Buffer b; + int i; +#ifdef UNICODE + TCHAR lua_wstring[4098]; +#endif + char lua_string[4098]; + lua_State *L = luaL_newstate(); + (void)argc; /* avoid "unused parameter" warning */ + luaL_openlibs(L); + lua_newtable(L); // create arg table + lua_pushstring(L, argv[0]); // add interpreter to arg table + lua_rawseti(L, -2, -1); + dwLength = GetModulePath( NULL, name, MAX_PATH ); + if(dwLength) { /* Optional bootstrap */ + strcat(name, ".lua"); + lua_pushstring(L, name); // add lua script to arg table + lua_rawseti(L, -2, 0); + lua_setglobal(L,"arg"); // set global arg table + if(!luaL_loadfile (L, name)) { + if(lua_pcall (L, 0, LUA_MULTRET, 0)) { + report (L); + lua_close (L); + return EXIT_FAILURE; + } + } + } + else + { + lua_pushstring(L, argv[0]); // no lua script, so add interpreter again, now as lua script + lua_rawseti(L, -2, 0); + lua_setglobal(L,"arg"); // set global arg table + } + + luaL_buffinit(L, &b); + for(i = 1; ; i++) { +#ifdef UNICODE + size = LoadString(GetModuleHandle(NULL), i, lua_wstring, + sizeof(lua_string)/sizeof(TCHAR)); + if(size > 0) wcstombs(lua_string, lua_wstring, size + 1); +#else + size = LoadString(GetModuleHandle(NULL), i, lua_string, + sizeof(lua_string)/sizeof(char)); +#endif + if(size) luaL_addlstring(&b, lua_string, size); else break; + } + luaL_pushresult(&b); + if (runlua (L, lua_tostring(L, -1), argc, argv)) { + report (L); + lua_close (L); + return EXIT_FAILURE; + } + lua_close (L); + return EXIT_SUCCESS; +} diff --git a/win32/bin/rclauncher.o b/win32/bin/rclauncher.o deleted file mode 100644 index 824d3b6e..00000000 Binary files a/win32/bin/rclauncher.o and /dev/null differ diff --git a/win32/bin/rclauncher.obj b/win32/bin/rclauncher.obj deleted file mode 100644 index 86a32795..00000000 Binary files a/win32/bin/rclauncher.obj and /dev/null differ -- cgit v1.2.3-55-g6feb