better handling of missing entry points

This commit is contained in:
Enno Rehling 2012-06-16 19:23:45 -07:00
parent 483615c458
commit 7618dc588d
1 changed files with 11 additions and 9 deletions

View File

@ -1286,7 +1286,7 @@ lua_State *lua_init(void) {
int eressea_run(lua_State *L, const char *luafile, const char *entry_point) int eressea_run(lua_State *L, const char *luafile, const char *entry_point)
{ {
int err; int err = 0;
global.vm_state = L; global.vm_state = L;
/* run the main script */ /* run the main script */
@ -1303,14 +1303,16 @@ int eressea_run(lua_State *L, const char *luafile, const char *entry_point)
} }
if (entry_point) { if (entry_point) {
lua_getglobal(L, entry_point); lua_getglobal(L, entry_point);
if (lua_isfunction(L, -1)) {
log_debug("calling entry-point: %s\n", entry_point);
err = lua_pcall(L, 0, 1, 0); err = lua_pcall(L, 0, 1, 0);
if (err != 0) { if (err != 0) {
log_lua_error(L); log_lua_error(L);
abort();
return err;
} }
return err;
} else { } else {
err = lua_console(L); log_error("unknown entry-point: %s\n", entry_point);
} }
return err; }
return lua_console(L);
} }