some logging and error reporting

This commit is contained in:
Enno Rehling 2010-02-21 20:47:09 +00:00
parent f37430e3c1
commit 9511f327b5
5 changed files with 12 additions and 30 deletions

View file

@ -30,6 +30,7 @@ int main(int argc, char ** argv)
{ {
int err; int err;
log_open("eressea.log");
load_config("eressea.ini"); load_config("eressea.ini");
err = eressea_init(); err = eressea_init();

View file

@ -193,10 +193,10 @@ void eressea_done(void)
static int static int
log_lua_error(lua_State * L) log_lua_error(lua_State * L)
{ {
static int s_abort_on_errors = 0; static int s_abort_on_errors = 1;
const char* error = lua_tostring(L, -1); const char* error = lua_tostring(L, -1);
log_error(("A LUA error occurred: %s\n", error)); log_error(("LUA call failed.\n%s\n", error));
lua_pop(L, 1); lua_pop(L, 1);
if (s_abort_on_errors) { if (s_abort_on_errors) {
@ -207,22 +207,27 @@ log_lua_error(lua_State * L)
int eressea_run(const char * luafile, const char * entry_point) int eressea_run(const char * luafile, const char * entry_point)
{ {
int err;
lua_State * L = (lua_State *)global.vm_state; lua_State * L = (lua_State *)global.vm_state;
/* run the main script */ /* run the main script */
if (luafile) { if (luafile) {
lua_getglobal(L, "dofile"); lua_getglobal(L, "dofile");
lua_pushstring(L, luafile); lua_pushstring(L, luafile);
if (lua_pcall(L, 1, 0, 0) != 0) { err = lua_pcall(L, 1, 0, 0);
if (err != 0) {
log_lua_error(L); log_lua_error(L);
return err;
} }
} }
if (entry_point) { if (entry_point) {
lua_getglobal(L, entry_point); lua_getglobal(L, entry_point);
if (lua_pcall(L, 0, 1, 0) != 0) { err = lua_pcall(L, 0, 1, 0);
if (err != 0) {
log_lua_error(L); log_lua_error(L);
return err;
} }
} else { } else {
lua_console(L); err = lua_console(L);
} }
return 0; return err;
} }

View file

@ -2226,7 +2226,6 @@ kernel_done(void)
* calling it is optional, e.g. a release server will most likely not do it. * calling it is optional, e.g. a release server will most likely not do it.
*/ */
translation_done(); translation_done();
skill_done();
gc_done(); gc_done();
sql_done(); sql_done();
} }
@ -3163,7 +3162,6 @@ void
kernel_init(void) kernel_init(void)
{ {
char zBuffer[MAX_PATH]; char zBuffer[MAX_PATH];
skill_init();
attrib_init(); attrib_init();
translation_init(); translation_init();

View file

@ -253,26 +253,6 @@ rc_skillmod(const struct race * rc, const region *r, skill_t sk)
return mods; return mods;
} }
void
skill_init(void)
{
}
void
skill_done(void)
{
#ifdef FASTER_SKILLMOD
int i;
for (i = 0;i!=RCMODMAXHASH;++i) {
while (modhash[i]) {
struct skillmods * mods = modhash[i];
modhash[i] = mods->next;
free(mods);
}
}
#endif
}
int int
level_days(int level) level_days(int level)
{ {

View file

@ -42,8 +42,6 @@ typedef struct skillmod_data {
extern struct attrib_type at_skillmod; extern struct attrib_type at_skillmod;
extern int rc_skillmod(const struct race * rc, const struct region *r, skill_t sk); extern int rc_skillmod(const struct race * rc, const struct region *r, skill_t sk);
extern int skillmod(const struct attrib * a, const struct unit * u, const struct region * r, skill_t sk, int value, int flags); extern int skillmod(const struct attrib * a, const struct unit * u, const struct region * r, skill_t sk, int value, int flags);
extern void skill_init(void);
extern void skill_done(void);
extern struct attrib * make_skillmod(skill_t sk, unsigned int flags, skillmod_fun special, double multiplier, int bonus); extern struct attrib * make_skillmod(skill_t sk, unsigned int flags, skillmod_fun special, double multiplier, int bonus);
extern const char * skillname(skill_t, const struct locale *); extern const char * skillname(skill_t, const struct locale *);