r446 - trunk
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Sun Jan 20 05:26:06 EST 2008
Author: icculus
Date: 2008-01-20 05:26:06 -0500 (Sun, 20 Jan 2008)
New Revision: 446
Modified:
trunk/lua_glue.c
trunk/lua_glue.h
trunk/platform.h
trunk/platform_unix.c
trunk/platform_windows.c
Log:
A couple things cleaned up and patched to compile, and uid/euid/gid supplied
to Lua scripts.
Modified: trunk/lua_glue.c
===================================================================
--- trunk/lua_glue.c 2008-01-20 10:03:16 UTC (rev 445)
+++ trunk/lua_glue.c 2008-01-20 10:26:06 UTC (rev 446)
@@ -86,7 +86,16 @@
lua_setfield(L, -2, sym);
} // set_string
+
+// Sets t[sym]=f, where t is on the top of the Lua stack.
// !!! FIXME: why is this a different naming convention?
+static inline void set_integer(lua_State *L, lua_Integer x, const char *sym)
+{
+ lua_pushinteger(L, x);
+ lua_setfield(L, -2, sym);
+} // set_string
+
+// !!! FIXME: why is this a different naming convention?
static inline void set_string_array(lua_State *L, int argc, const char **argv,
const char *sym)
{
@@ -1483,43 +1492,25 @@
boolean MojoLua_initLua(void)
{
const char *envr = cmdlinestr("locale", "MOJOSETUP_LOCALE", NULL);
- char *homedir = NULL;
- char *binarypath = NULL;
- char *locale = NULL
- char *ostype = NULL;
- char *osversion = NULL;
+ char *homedir = MojoPlatform_homedir();
+ char *binarypath = MojoPlatform_appBinaryPath();
+ char *locale = (envr != NULL) ? xstrdup(envr) : MojoPlatform_locale();
+ char *ostype = MojoPlatform_osType();
+ char *osversion = MojoPlatform_osVersion();
+ lua_Integer uid = MojoPlatform_getuid();
+ lua_Integer euid = MojoPlatform_geteuid();
+ lua_Integer gid = MojoPlatform_getgid();
- if (envr != NULL)
- locale = xstrdup(envr);
- else if ((locale = MojoPlatform_locale()) == NULL)
- locale = xstrdup("???");
+ if (locale == NULL) locale = xstrdup("???");
+ if (ostype == NULL) ostype = xstrdup("???");
+ if (osversion == NULL) osversion = xstrdup("???");
- if ((ostype = MojoPlatform_osType()) == NULL)
- ostype = xstrdup("???");
-
- if ((osversion = MojoPlatform_osVersion()) == NULL)
- osversion = xstrdup("???");
-
assert(luaState == NULL);
-
- luaState = lua_newstate(MojoLua_alloc, NULL);
- if (luaState == NULL)
- return false;
-
+ luaState = lua_newstate(MojoLua_alloc, NULL); // calls fatal() on failure.
lua_atpanic(luaState, luahook_fatal);
-
- if (!lua_checkstack(luaState, 20)) // Just in case.
- {
- lua_close(luaState);
- luaState = NULL;
- return false;
- } // if
-
+ assert(lua_checkstack(luaState, 20)); // Just in case.
registerLuaLibs(luaState);
- homedir = MojoPlatform_homedir();
- binarypath = MojoPlatform_appBinaryPath();
-
// !!! 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...
@@ -1568,6 +1559,9 @@
set_string(luaState, homedir, "homedir");
set_string(luaState, binarypath, "binarypath");
set_string(luaState, GBaseArchivePath, "basearchivepath");
+ set_integer(luaState, uid, "uid");
+ set_integer(luaState, euid, "euid");
+ set_integer(luaState, gid, "gid");
set_string_array(luaState, GArgc, GArgv, "argv");
lua_newtable(luaState);
set_string(luaState, "base", "base");
@@ -1621,11 +1615,11 @@
lua_setfield(luaState, -2, "archive");
lua_setglobal(luaState, MOJOSETUP_NAMESPACE);
- free(binarypath);
- free(homedir);
free(osversion);
free(ostype);
free(locale);
+ free(binarypath);
+ free(homedir);
// Transfer control to Lua to setup some APIs and state...
if (!MojoLua_runFile("mojosetup_init"))
Modified: trunk/lua_glue.h
===================================================================
--- trunk/lua_glue.h 2008-01-20 10:03:16 UTC (rev 445)
+++ trunk/lua_glue.h 2008-01-20 10:26:06 UTC (rev 446)
@@ -34,7 +34,7 @@
// Will return false if the file couldn't be loaded, or true if the chunk
// successfully ran. Will not return if there's a runtime error in the
// chunk, as it will call fatal() instead.
-boolean MojoLua_runFileFromDir(const char *dir, const char *name)
+boolean MojoLua_runFileFromDir(const char *dir, const char *name);
// This is shorthand for MojoLua_runFileFromDir("scripts", fname);
boolean MojoLua_runFile(const char *fname);
Modified: trunk/platform.h
===================================================================
--- trunk/platform.h 2008-01-20 10:03:16 UTC (rev 445)
+++ trunk/platform.h 2008-01-20 10:26:06 UTC (rev 446)
@@ -274,7 +274,16 @@
// Caller must free() the returned pointer!
char *MojoPlatform_osVersion(void);
+// !!! FIXME: document me.
+uint64 MojoPlatform_getuid(void);
+// !!! FIXME: document me.
+uint64 MojoPlatform_geteuid(void);
+
+// !!! FIXME: document me.
+uint64 MojoPlatform_getgid(void);
+
+
// Basic platform detection.
#if PLATFORM_WINDOWS
#define PLATFORM_NAME "windows"
Modified: trunk/platform_unix.c
===================================================================
--- trunk/platform_unix.c 2008-01-20 10:03:16 UTC (rev 445)
+++ trunk/platform_unix.c 2008-01-20 10:26:06 UTC (rev 446)
@@ -370,6 +370,7 @@
char *MojoPlatform_locale(void)
{
char *retval = NULL;
+ char *ptr = NULL;
const char *envr = getenv("LANG");
if (envr != NULL)
{
@@ -399,7 +400,7 @@
if (locale != NULL)
{
const CFIndex len = (CFStringGetLength(locale) + 1) * 6;
- char *ptr = (char*) xmalloc(len);
+ ptr = (char*) xmalloc(len);
CFStringGetCString(locale, ptr, len, kCFStringEncodingUTF8);
CFRelease(locale);
retval = xrealloc(ptr, strlen(ptr) + 1);
@@ -454,10 +455,12 @@
long ver = 0x0000;
if (Gestalt(gestaltSystemVersion, &ver) == noErr)
{
- char *retval = (char *) xmalloc(16);
+ const size_t len = 8;
+ char *buf = (char *) xmalloc(len);
+ char str[16];
snprintf(str, sizeof (str), "%X", (int) ver);
snprintf(buf, len, "%c%c.%c.%c", str[0], str[1], str[2], str[3]);
- return retval;
+ return buf;
} // if
#else
// This information may or may not actually MEAN anything. On BeOS, it's
@@ -1114,6 +1117,24 @@
} // MojoPlatform_decodeImage
+uint64 MojoPlatform_getuid(void)
+{
+ return (uint64) getuid();
+} // MojoPlatform_getuid
+
+
+uint64 MojoPlatform_geteuid(void)
+{
+ return (uint64) geteuid();
+} // MojoPlatform_geteuid
+
+
+uint64 MojoPlatform_getgid(void)
+{
+ return (uint64) getgid();
+} // MojoPlatform_getgid
+
+
static void signal_catcher(int sig)
{
static boolean first_shot = true;
Modified: trunk/platform_windows.c
===================================================================
--- trunk/platform_windows.c 2008-01-20 10:03:16 UTC (rev 445)
+++ trunk/platform_windows.c 2008-01-20 10:26:06 UTC (rev 446)
@@ -1586,6 +1586,25 @@
} // MojoPlatform_dlclose
+uint64 MojoPlatform_getuid(void)
+{
+ return 0; // !!! FIXME
+} // MojoPlatform_getuid
+
+
+uint64 MojoPlatform_geteuid(void)
+{
+ return 0; // !!! FIXME
+} // MojoPlatform_geteuid
+
+
+uint64 MojoPlatform_getgid(void)
+{
+ return 0; // !!! FIXME
+} // MojoPlatform_getgid
+
+
+
// Get OS info and save the important parts.
// Returns non-zero if successful, otherwise it returns zero on failure.
static boolean getOSInfo(void)
More information about the mojosetup-commits
mailing list