$NetBSD: patch-ai,v 1.3 2006/08/14 22:43:08 wiz Exp $ --- src/celestia/celx.cpp.orig 2006-01-07 00:01:51.000000000 +0000 +++ src/celestia/celx.cpp @@ -368,6 +368,18 @@ static CelestiaCore* getAppCore(lua_Stat return appCore; } +static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { + (void)ud; /* not used */ + (void)osize; /* not used */ + if (nsize == 0) { + free(ptr); /* ANSI requires that free(NULL) has no effect */ + return NULL; + } + else + /* ANSI requires that realloc(NULL, size) == malloc(size) */ + return realloc(ptr, nsize); +} + LuaState::LuaState() : timeout(MaxTimeslice), @@ -378,7 +390,7 @@ LuaState::LuaState() : scriptAwakenTime(0.1), ioMode(NoIO) { - state = lua_open(); + state = lua_newstate(l_alloc, NULL); timer = CreateTimer(); screenshotCount = 0; } @@ -472,6 +484,7 @@ void LuaState::cleanup() } + bool LuaState::createThread() { // Initialize the coroutine which wraps the script @@ -598,7 +611,7 @@ bool LuaState::charEntered(const char* c int stackTop = lua_gettop(costate); if (strcmp(c_p, "y") == 0) { - lua_iolibopen(costate); + luaopen_io(costate); ioMode = IOAllowed; } else @@ -4577,10 +4590,10 @@ bool LuaState::init(CelestiaCore* appCor initMaps(); // Import the base and math libraries - lua_baselibopen(state); - lua_mathlibopen(state); - lua_tablibopen(state); - lua_strlibopen(state); + luaopen_base(state); + luaopen_math(state); + luaopen_table(state); + luaopen_string(state); // Add an easy to use wait function, so that script writers can // live in ignorance of coroutines. There will probably be a significant