Skip to content

Commit

Permalink
Added MojoSetup.info.homedir string.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed May 10, 2007
1 parent 1c0f412 commit c5a1ece
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lua_glue.c
Expand Up @@ -1207,6 +1207,7 @@ static int luahook_date(lua_State *L)
boolean MojoLua_initLua(void)
{
const char *envr = cmdlinestr("locale", "MOJOSETUP_LOCALE", NULL);
char *homedir = NULL;
char locale[16];
char ostype[64];
char osversion[64];
Expand Down Expand Up @@ -1238,6 +1239,8 @@ boolean MojoLua_initLua(void)

registerLuaLibs(luaState);

homedir = MojoPlatform_homedir();

// !!! FIXME: I'd like to change the function name case for the lua hooks.

// Build MojoSetup namespace for Lua to access and fill in C bridges...
Expand Down Expand Up @@ -1278,6 +1281,7 @@ boolean MojoLua_initLua(void)
set_string(luaState, GMojoSetupLicense, "license");
set_string(luaState, GLuaLicense, "lualicense");
set_string(luaState, logLevelString(), "loglevel");
set_string(luaState, homedir, "homedir");
set_string_array(luaState, GArgc, GArgv, "argv");
lua_newtable(luaState);
set_string(luaState, "base", "base");
Expand Down Expand Up @@ -1325,6 +1329,8 @@ boolean MojoLua_initLua(void)
lua_setfield(luaState, -2, "archive");
lua_setglobal(luaState, MOJOSETUP_NAMESPACE);

free(homedir);

// Set up localization table, if possible.
MojoLua_runFile("localization");

Expand Down
3 changes: 3 additions & 0 deletions platform.h
Expand Up @@ -13,6 +13,9 @@ int MojoSetup_main(int argc, char **argv);
// Caller must free returned string!
char *MojoPlatform_appBinaryPath(void);

// Caller must free returned string!
char *MojoPlatform_homedir(void);

uint32 MojoPlatform_ticks(void);

// Make current process kill itself immediately, without any sort of internal
Expand Down
7 changes: 7 additions & 0 deletions platform_unix.c
Expand Up @@ -316,6 +316,13 @@ char *MojoPlatform_appBinaryPath(void)
} // MojoPlatform_appBinaryPath


char *MojoPlatform_homedir(void)
{
const char *envr = getenv("HOME");
return xstrdup(envr ? envr : "/");
} // MojoPlatform_homedir


// This implementation is a bit naive.
boolean MojoPlatform_locale(char *buf, size_t len)
{
Expand Down

0 comments on commit c5a1ece

Please sign in to comment.