Skip to content

Commit

Permalink
Expose a MojoSetup.runScript function to allow running a non LUA script
Browse files Browse the repository at this point in the history
contained in the installation media from the LUA environment.
  • Loading branch information
jwhite66 committed Jun 9, 2010
1 parent b5d82e3 commit 8ab059c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs.txt
Expand Up @@ -1085,6 +1085,12 @@ Your config file is a Lua script, and as such, has access to all of Lua's
runtime, as require() won't respect the Base Archive.


runScript (script, devnull, args...)

Run the given script in a shell. If devnull is non zero, all stdout
and stderr will be directed to /dev/null.


MojoSetup.translate(str)

Find the proper translation for the end user's locale in the localization
Expand Down
15 changes: 15 additions & 0 deletions lua_glue.c
Expand Up @@ -1111,6 +1111,20 @@ static int luahook_platform_exec(lua_State *L)
return retvalBoolean(L, 0);
} // luahook_platform_exec

static int luahook_platform_runscript(lua_State *L)
{
const char *script = luaL_checkstring(L, 1);
const boolean devnull = luaL_checkinteger(L, 2);
const int argc = lua_gettop(L);
const char *argv[11];
int i;

for (i = 0; i < argc - 2 && i < (sizeof(argv) / sizeof(argv[0]) - 1); i++)
argv[i] = luaL_checkstring(L, i + 3);
argv[i] = NULL;

return retvalNumber(L, MojoPlatform_runScript(script, devnull, argv));
} // luahook_platform_exec

static int luahook_movefile(lua_State *L)
{
Expand Down Expand Up @@ -1820,6 +1834,7 @@ boolean MojoLua_initLua(void)
set_cfunc(luaState, luahook_platform_installdesktopmenuitem, "installdesktopmenuitem");
set_cfunc(luaState, luahook_platform_uninstalldesktopmenuitem, "uninstalldesktopmenuitem");
set_cfunc(luaState, luahook_platform_exec, "exec");
set_cfunc(luaState, luahook_platform_runscript, "runscript");
lua_setfield(luaState, -2, "platform");

// Set the GUI functions...
Expand Down
3 changes: 3 additions & 0 deletions platform.h
Expand Up @@ -245,6 +245,9 @@ boolean MojoPlatform_installDesktopMenuItem(const char *data);
// Returns (true) on success and (false) on failure.
boolean MojoPlatform_uninstallDesktopMenuItem(const char *data);

// Run a script from the archive in the OS
int MojoPlatform_runScript(const char *script, boolean devnull, const char **argv);

// Exec a given process name
int MojoPlatform_exec(const char *cmd);

Expand Down
10 changes: 8 additions & 2 deletions platform_unix.c
Expand Up @@ -1056,10 +1056,12 @@ static int runScriptString(const char *str, boolean devnull, const char **_argv)

return retval;
} // runScriptString
#endif


static int runScript(const char *script, boolean devnull, const char **argv)
int MojoPlatform_runScript(const char *script, boolean devnull, const char **argv)
{
#if !PLATFORM_MACOSX && !PLATFORM_BEOS
int retval = 127;
char *str = NULL;
MojoInput *in = MojoInput_newFromArchivePath(GBaseArchive, script);
Expand All @@ -1086,9 +1088,13 @@ static int runScript(const char *script, boolean devnull, const char **argv)

free(str);
return retval;
#else
STUBBED("runScript");
#endif
} // runScript


#if !PLATFORM_MACOSX && !PLATFORM_BEOS
static char *shellEscape(const char *str)
{
size_t len = 0;
Expand Down Expand Up @@ -1163,7 +1169,7 @@ static boolean unix_launchXdgUtil(const char *util, const char **argv)
else // try our fallback copy of xdg-utils in GBaseArchive?
{
char *script = format("meta/xdg-utils/%0", util);
rc = runScript(script, true, argv);
rc = MojoPlatform_runScript(script, true, argv);
logDebug("internal script '%0' returned %1", script, numstr(rc));
free(script);
} // if
Expand Down
5 changes: 5 additions & 0 deletions platform_windows.c
Expand Up @@ -524,6 +524,11 @@ int MojoPlatform_exec(const char *cmd)
} // MojoPlatform_exec


int MojoPlatform_runScript(const char *script, boolean devnull, const char **argv)
{
STUBBED("runScript");
return 0;
}

boolean MojoPlatform_spawnTerminal(void)
{
Expand Down

0 comments on commit 8ab059c

Please sign in to comment.