Compiles with LUA 5.0, too

This commit is contained in:
Enno Rehling 2007-06-11 23:56:04 +00:00
parent 8c57e05798
commit 9d72640755
2 changed files with 50 additions and 15 deletions

View File

@ -21,25 +21,39 @@
#include <lua.hpp> #include <lua.hpp>
#include <luabind/luabind.hpp> #include <luabind/luabind.hpp>
static const struct {
const char * name;
int (*func)(lua_State *);
} lualibs[] = {
{"", luaopen_base},
{LUA_TABLIBNAME, luaopen_table},
{LUA_IOLIBNAME, luaopen_io},
{LUA_STRLIBNAME, luaopen_string},
{LUA_MATHLIBNAME, luaopen_math},
{ NULL, NULL }
};
static void
openlibs(lua_State * L)
{
int i;
for (i=0;lualibs[i].func;++i) {
lua_pushcfunction(L, lualibs[i].func);
lua_pushstring(L, lualibs[i].name);
lua_call(L, 1, 0);
}
}
static lua_State * static lua_State *
lua_init(void) lua_init(void)
{ {
lua_State * L = lua_open(); lua_State * L = lua_open();
/*
luaopen_base(L); openlibs(L);
luaopen_math(L);
luaopen_string(L);
luaopen_io(L);
luaopen_table(L);
*/
luaL_openlibs(L);
luabind::open(L); luabind::open(L);
bind_objects(L); bind_objects(L);
bind_eressea(L); bind_eressea(L);
// bind_script(L);
// bind_message(L);
// bind_event(L);
bind_spell(L); bind_spell(L);
bind_alliance(L); bind_alliance(L);
bind_region(L); bind_region(L);
@ -56,9 +70,6 @@ lua_init(void)
static void static void
lua_done(lua_State * L) lua_done(lua_State * L)
{ {
#if 0
reset_scripts();
#endif
lua_close(L); lua_close(L);
} }

View File

@ -258,6 +258,29 @@ game_init(void)
#endif #endif
} }
static const struct {
const char * name;
int (*func)(lua_State *);
} lualibs[] = {
{"", luaopen_base},
{LUA_TABLIBNAME, luaopen_table},
{LUA_IOLIBNAME, luaopen_io},
{LUA_STRLIBNAME, luaopen_string},
{LUA_MATHLIBNAME, luaopen_math},
{ NULL, NULL }
};
static void
openlibs(lua_State * L)
{
int i;
for (i=0;lualibs[i].func;++i) {
lua_pushcfunction(L, lualibs[i].func);
lua_pushstring(L, lualibs[i].name);
lua_call(L, 1, 0);
}
}
static lua_State * static lua_State *
lua_init(void) lua_init(void)
{ {
@ -268,8 +291,9 @@ lua_init(void)
luaopen_string(luaState); luaopen_string(luaState);
luaopen_io(luaState); luaopen_io(luaState);
luaopen_table(luaState); luaopen_table(luaState);
*/
luaL_openlibs(luaState); luaL_openlibs(luaState);
*/
openlibs(luaState);
luabind::open(luaState); luabind::open(luaState);
bind_objects(luaState); bind_objects(luaState);
bind_eressea(luaState); bind_eressea(luaState);