2010-08-08 10:06:34 +02:00
|
|
|
|
#include <platform.h>
|
|
|
|
|
#include "settings.h"
|
|
|
|
|
#include "eressea.h"
|
|
|
|
|
|
|
|
|
|
#include <kernel/config.h>
|
|
|
|
|
#include <util/console.h>
|
|
|
|
|
#include <util/log.h>
|
|
|
|
|
|
|
|
|
|
/* lua includes */
|
|
|
|
|
#ifdef BINDINGS_TOLUA
|
|
|
|
|
#include <lua.h>
|
|
|
|
|
#include <lualib.h>
|
|
|
|
|
#include <lauxlib.h>
|
|
|
|
|
#include <bindings/bindings.h>
|
|
|
|
|
#include <bindings/helpers.h>
|
2012-06-05 01:23:02 +02:00
|
|
|
|
#ifdef BSON_ATTRIB
|
|
|
|
|
# include <bindings/bind_attrib.h>
|
|
|
|
|
#endif
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <bindings/bind_building.h>
|
|
|
|
|
#include <bindings/bind_faction.h>
|
|
|
|
|
#include <bindings/bind_gmtool.h>
|
|
|
|
|
#include <bindings/bind_hashtable.h>
|
|
|
|
|
#include <bindings/bind_message.h>
|
|
|
|
|
#include <bindings/bind_region.h>
|
|
|
|
|
#include <bindings/bind_ship.h>
|
|
|
|
|
#include <bindings/bind_storage.h>
|
|
|
|
|
#include <bindings/bind_unit.h>
|
2011-03-07 17:26:50 +01:00
|
|
|
|
#endif /* BINDINGS_TOLUA */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
#if MUSEUM_MODULE
|
|
|
|
|
#include <modules/museum.h>
|
|
|
|
|
#endif
|
|
|
|
|
#if ARENA_MODULE
|
|
|
|
|
#include <modules/arena.h>
|
|
|
|
|
#endif
|
|
|
|
|
#include <triggers/triggers.h>
|
|
|
|
|
#include <util/language.h>
|
|
|
|
|
#include <kernel/xmlreader.h>
|
|
|
|
|
#include <kernel/reports.h>
|
|
|
|
|
#include <kernel/item.h>
|
|
|
|
|
#include <kernel/names.h>
|
|
|
|
|
#include <kernel/reports.h>
|
|
|
|
|
#include <kernel/building.h>
|
|
|
|
|
#include <modules/wormhole.h>
|
|
|
|
|
#include <modules/gmcmd.h>
|
|
|
|
|
#include <modules/xmas.h>
|
|
|
|
|
#include <gamecode/archetype.h>
|
|
|
|
|
#include <gamecode/report.h>
|
|
|
|
|
#include <gamecode/items.h>
|
|
|
|
|
#include <gamecode/creport.h>
|
|
|
|
|
#include <gamecode/xmlreport.h>
|
|
|
|
|
#include <items/itemtypes.h>
|
|
|
|
|
#include <attributes/attributes.h>
|
|
|
|
|
|
|
|
|
|
static const struct {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *name;
|
|
|
|
|
int (*func) (lua_State *);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} lualibs[] = {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
{
|
|
|
|
|
"", luaopen_base}, {
|
|
|
|
|
LUA_TABLIBNAME, luaopen_table}, {
|
|
|
|
|
LUA_IOLIBNAME, luaopen_io}, {
|
|
|
|
|
LUA_STRLIBNAME, luaopen_string}, {
|
|
|
|
|
LUA_MATHLIBNAME, luaopen_math}, {
|
|
|
|
|
LUA_LOADLIBNAME, luaopen_package}, {
|
|
|
|
|
LUA_DBLIBNAME, luaopen_debug},
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#if LUA_VERSION_NUM>=501
|
2011-03-07 08:02:35 +01:00
|
|
|
|
{
|
|
|
|
|
LUA_OSLIBNAME, luaopen_os},
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#endif
|
2011-03-07 08:02:35 +01:00
|
|
|
|
{
|
|
|
|
|
NULL, NULL}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void openlibs(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int i;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (i = 0; lualibs[i].func; ++i) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
lua_pushcfunction(L, lualibs[i].func);
|
|
|
|
|
lua_pushstring(L, lualibs[i].name);
|
|
|
|
|
lua_call(L, 1, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void lua_done(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
lua_close(L);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static lua_State *lua_init(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
lua_State *L = lua_open();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
openlibs(L);
|
|
|
|
|
#ifdef BINDINGS_TOLUA
|
|
|
|
|
register_tolua_helpers();
|
|
|
|
|
tolua_eressea_open(L);
|
|
|
|
|
tolua_sqlite_open(L);
|
|
|
|
|
tolua_unit_open(L);
|
|
|
|
|
tolua_building_open(L);
|
|
|
|
|
tolua_ship_open(L);
|
|
|
|
|
tolua_region_open(L);
|
|
|
|
|
tolua_faction_open(L);
|
2012-06-05 01:23:02 +02:00
|
|
|
|
#ifdef BSON_ATTRIB
|
2010-08-08 10:06:34 +02:00
|
|
|
|
tolua_attrib_open(L);
|
2012-06-05 01:23:02 +02:00
|
|
|
|
#endif
|
2010-08-08 10:06:34 +02:00
|
|
|
|
tolua_unit_open(L);
|
|
|
|
|
tolua_message_open(L);
|
|
|
|
|
tolua_hashtable_open(L);
|
|
|
|
|
tolua_gmtool_open(L);
|
|
|
|
|
tolua_storage_open(L);
|
|
|
|
|
#endif
|
|
|
|
|
return L;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void game_done(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
#ifdef CLEANUP_CODE
|
|
|
|
|
/* Diese Routine enfernt allen allokierten Speicher wieder. Das ist nur
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* zum Debugging interessant, wenn man Leak Detection hat, und nach
|
|
|
|
|
* nicht freigegebenem Speicher sucht, der nicht bis zum Ende ben<EFBFBD>tigt
|
|
|
|
|
* wird (tempor<EFBFBD>re Hilsstrukturen) */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
free_game();
|
|
|
|
|
|
|
|
|
|
creport_cleanup();
|
|
|
|
|
#ifdef REPORT_FORMAT_NR
|
|
|
|
|
report_cleanup();
|
|
|
|
|
#endif
|
|
|
|
|
calendar_cleanup();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void game_init(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
register_triggers();
|
|
|
|
|
register_xmas();
|
|
|
|
|
|
|
|
|
|
register_reports();
|
|
|
|
|
register_nr();
|
|
|
|
|
register_cr();
|
|
|
|
|
register_xr();
|
|
|
|
|
|
|
|
|
|
register_names();
|
|
|
|
|
register_resources();
|
|
|
|
|
register_buildings();
|
|
|
|
|
register_itemfunctions();
|
|
|
|
|
#if DUNGEON_MODULE
|
|
|
|
|
register_dungeon();
|
|
|
|
|
#endif
|
|
|
|
|
#if MUSEUM_MODULE
|
|
|
|
|
register_museum();
|
|
|
|
|
#endif
|
|
|
|
|
#if ARENA_MODULE
|
|
|
|
|
register_arena();
|
|
|
|
|
#endif
|
|
|
|
|
register_wormholes();
|
|
|
|
|
|
|
|
|
|
register_itemtypes();
|
|
|
|
|
register_xmlreader();
|
|
|
|
|
register_archetypes();
|
|
|
|
|
enable_xml_gamecode();
|
|
|
|
|
|
|
|
|
|
register_attributes();
|
|
|
|
|
register_gmcmd();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int eressea_init(void)
|
|
|
|
|
{
|
|
|
|
|
global.vm_state = lua_init();
|
|
|
|
|
kernel_init();
|
|
|
|
|
game_init();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void eressea_done(void)
|
|
|
|
|
{
|
|
|
|
|
game_done();
|
|
|
|
|
kernel_done();
|
2011-03-07 08:02:35 +01:00
|
|
|
|
lua_done((lua_State *) global.vm_state);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int eressea_run(const char *luafile, const char *entry_point)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int err;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
lua_State *L = (lua_State *) global.vm_state;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* run the main script */
|
|
|
|
|
if (luafile) {
|
|
|
|
|
lua_getglobal(L, "dofile");
|
|
|
|
|
lua_pushstring(L, luafile);
|
|
|
|
|
err = lua_pcall(L, 1, 0, 0);
|
|
|
|
|
if (err != 0) {
|
|
|
|
|
log_lua_error(L);
|
|
|
|
|
abort();
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (entry_point) {
|
|
|
|
|
lua_getglobal(L, entry_point);
|
|
|
|
|
err = lua_pcall(L, 0, 1, 0);
|
|
|
|
|
if (err != 0) {
|
|
|
|
|
log_lua_error(L);
|
|
|
|
|
abort();
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
err = lua_console(L);
|
|
|
|
|
}
|
|
|
|
|
return err;
|
|
|
|
|
}
|