From fa5dc43b98a4af95eb64c8477363f25dd0364567 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 20 Apr 2014 09:36:25 -0700 Subject: [PATCH] reorganizing the way configuration data is read (WIP) --- cutest | 2 +- res/e3a/buildings.xml | 2 +- res/e3a/races.xml | 55 ++++++++++++++++++++++--------------------- res/e3a/resources.xml | 14 +++++------ res/e3a/weapons.xml | 44 +++++++++++++++++----------------- s/install | 19 +++++++++++++++ src/bindings.c | 55 +++++++++++++++++++++++-------------------- src/main.c | 6 ++++- src/util/xml.c | 2 +- 9 files changed, 113 insertions(+), 86 deletions(-) create mode 100755 s/install diff --git a/cutest b/cutest index 788659594..d83cec09a 160000 --- a/cutest +++ b/cutest @@ -1 +1 @@ -Subproject commit 788659594ef87e9f497b8039da764182adfd2943 +Subproject commit d83cec09a52835274ab8ed4849de16fb8658982a diff --git a/res/e3a/buildings.xml b/res/e3a/buildings.xml index f87987ac1..b3e59f0a4 100644 --- a/res/e3a/buildings.xml +++ b/res/e3a/buildings.xml @@ -1,7 +1,7 @@ - + diff --git a/res/e3a/races.xml b/res/e3a/races.xml index 3c28a2319..0e5166d42 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -3,11 +3,35 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -583,29 +607,6 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/res/e3a/resources.xml b/res/e3a/resources.xml index bd71f8c5d..4ab29a5b6 100644 --- a/res/e3a/resources.xml +++ b/res/e3a/resources.xml @@ -2,13 +2,13 @@ - - - - - - - + + + + + + + diff --git a/res/e3a/weapons.xml b/res/e3a/weapons.xml index 687d12d21..91748d64e 100644 --- a/res/e3a/weapons.xml +++ b/res/e3a/weapons.xml @@ -1,25 +1,25 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + diff --git a/s/install b/s/install new file mode 100755 index 000000000..359254e6a --- /dev/null +++ b/s/install @@ -0,0 +1,19 @@ +#!/bin/sh +ROOT=$(pwd) +while [ ! -d $ROOT/.git ]; do + ROOT=$(dirname $ROOT) + if [ "$ROOT" == "/" ; then + echo "could not find root, are you in the git repository?" + exit + fi +done + +MACHINE=`uname -m` +[ -z "$CC" ] && [ ! -z `which gcc` ] && CC="gcc" +[ -z "$CC" ] && [ ! -z `which tcc` ] && CC="tcc" +[ -z "$CC" ] && [ ! -z `which cc` ] && CC="cc" +BIN_DIR="build-$MACHINE-$CC-Debug" + +cd $ROOT/$BIN_DIR +make install +cd - diff --git a/src/bindings.c b/src/bindings.c index bcf7f76f3..7a8e99e3a 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -1198,33 +1198,36 @@ lua_State *lua_init(void) { int eressea_run(lua_State *L, const char *luafile, const char *entry_point) { - int err = 0; + int err = 0; - global.vm_state = L; - /* run the main script */ - if (luafile) { - log_debug("executing script %s\n", 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; + global.vm_state = L; + /* run the main script */ + if (luafile) { + log_debug("executing script %s\n", 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); - if (lua_isfunction(L, -1)) { - log_debug("calling entry-point: %s\n", entry_point); - err = lua_pcall(L, 0, 1, 0); - if (err != 0) { - log_lua_error(L); - } - return err; - } else { - log_error("unknown entry-point: %s\n", entry_point); + if (entry_point) { + if (strcmp("console", entry_point)==0) { + return lua_console(L); + } + 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); + if (err != 0) { + log_lua_error(L); + } + return err; + } else { + log_error("unknown entry-point: %s\n", entry_point); + } } - } - return lua_console(L); + return 0; } diff --git a/src/main.c b/src/main.c index ddd81e4ff..2246dc389 100644 --- a/src/main.c +++ b/src/main.c @@ -72,6 +72,7 @@ static int usage(const char *prog, const char *arg) } fprintf(stderr, "Usage: %s [options]\n" "-t : read this datafile, not the most current one\n" + "-f : execute a lua script\n" "-q : be quite (same as -v 0)\n" "-v : verbosity level\n" "-C : run in interactive mode\n" @@ -117,7 +118,10 @@ static int parse_args(int argc, char **argv, int *exitcode) const char *arg; switch (argv[i][1]) { case 'C': - entry_point = NULL; + entry_point = "console"; + break; + case 'f': + i = get_arg(argc, argv, 2, i, &luafile, 0); break; case 'l': i = get_arg(argc, argv, 2, i, &logfile, 0); diff --git a/src/util/xml.c b/src/util/xml.c index 2339733fa..c97460912 100644 --- a/src/util/xml.c +++ b/src/util/xml.c @@ -118,7 +118,7 @@ int read_xml(const char *filename, const char *catalog) doc = xmlParseFile(filename); #endif if (doc == NULL) { - log_error("could not open %s\n", filename); + log_error("could not open '%s'\n", filename); return -1; }