diff --git a/src/Jamrules b/src/Jamrules index f56b9558f..6db60d2d5 100644 --- a/src/Jamrules +++ b/src/Jamrules @@ -4,9 +4,9 @@ LINK = gcc ; MSPACES = 1 ; -# BINDING = LUABIND ; -if ! $(BINDING) { - BINDING = TOLUA ; +# BINDINGS = LUABIND ; +if ! $(BINDINGS) { + BINDINGS = TOLUA ; } if ! $(LUA_VERSION) { @@ -104,14 +104,17 @@ rule zlib LINKLIBS on $(<) += -lz ; } -rule luabind +rule liblua { - LINKLIBS on $(<) += -L$(LUABIND_ROOT)/lib ; if $(LUA_VERSION) = 5.1 { LINKLIBS on $(<) += -llua5.1 ; } else { LINKLIBS on $(<) += -llua50 -llualib50 ; } +} + +rule libluabind +{ LINKLIBS on $(<) += -lm -lluabind ; } @@ -120,6 +123,23 @@ rule libxml2 LINKLIBS on $(<) += -lxml2 ; } +rule libtolua +{ + LINKLIBS on $(<) += -ltolua ; +} + +rule libcurses +{ + LINKLIBS on $(<) += -lncurses ; +} + +rule libmcheck +{ + if $(DEBUG) = 1 { + LINKLIBS on $(<) += -lmcheck ; + } +} + rule UsingLuabind { SubDirHdrs $(LUABIND_ROOT)/include ; diff --git a/src/common/kernel/building.h b/src/common/kernel/building.h index 2edcf5f39..86ffd069e 100644 --- a/src/common/kernel/building.h +++ b/src/common/kernel/building.h @@ -14,7 +14,9 @@ #ifndef H_KRNL_BUILDING #define H_KRNL_BUILDING +#include #include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/eressea/Jamfile b/src/eressea/Jamfile index d0b557f80..24e55a437 100644 --- a/src/eressea/Jamfile +++ b/src/eressea/Jamfile @@ -12,7 +12,12 @@ UsingLuabind ; SEARCH_SOURCE += [ FDirName $(TOP) common iniparser ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) curses ] ; -SEARCH_SOURCE += [ FDirName $(SUBDIR) lua ] ; +if $(BINDINGS) = LUABIND { + SEARCH_SOURCE += [ FDirName $(SUBDIR) lua ] ; +} +if $(BINDINGS) = TOLUA { + SEARCH_SOURCE += [ FDirName $(SUBDIR) tolua ] ; +} SubDirC++Flags -DHAVE_LUA ; SubDirHdrs $(XMLHDRS) ; @@ -21,7 +26,20 @@ LUASERVER = eressea-lua ; SERVER_SOURCES = main.c korrektur.c ; -SHARED_BINDINGS = +TOLUA_SOURCES = + bindings.c + helpers.c + bind_unit.c + bind_ship.c + bind_faction.c + bind_region.c + bind_message.c + bind_hashtable.c + bind_building.c + bind_gmtool.c +; + +LUABIND_SOURCES = alliance.cpp building.cpp eressea.cpp @@ -35,15 +53,23 @@ SHARED_BINDINGS = unit.cpp item.cpp test.cpp -; - -Library luabindings : $(SHARED_BINDINGS) ; - -LUASERVER_SOURCES = - iniparser.c gm.cpp script.cpp gamecode.cpp +; + +if $(BINDINGS) = LUABIND { + Library bindings : $(LUABIND_SOURCES) ; + libluabind $(LUASERVER) ; +} +if $(BINDINGS) = TOLUA { + Library bindings : $(TOLUA_SOURCES) ; + libtolua $(LUASERVER) ; +} +liblua $(LUASERVER) ; + +LUASERVER_SOURCES = + iniparser.c listbox.c server.cpp korrektur.c @@ -54,11 +80,10 @@ LUASERVER_SOURCES = # eressea-server with lua scripting LinkLibraries $(LUASERVER) : - luabindings gamecode items spells kernel modules attributes races triggers util ; -luabind $(LUASERVER) ; + bindings gamecode items spells kernel modules attributes races triggers util ; libxml2 $(LUASERVER) ; -LINKLIBS on $(LUASERVER) += -lm -ldl -lstdc++ -lncurses ; -if $(DEBUG) = 1 { - LINKLIBS on $(LUASERVER) += -lmcheck ; -} +libcurses $(LUASERVER) ; +libmcheck $(LUASERVER) ; + +LINKLIBS on $(LUASERVER) += -lm -ldl -lstdc++ ; Main $(LUASERVER) : $(LUASERVER_SOURCES) ; diff --git a/src/eressea/gmtool.h b/src/eressea/gmtool.h index a60c37a83..60833361f 100644 --- a/src/eressea/gmtool.h +++ b/src/eressea/gmtool.h @@ -17,6 +17,7 @@ extern "C" { struct lua_State; struct selection; struct state; + struct region; extern int gmmain(int argc, char *argv[]); extern int curses_readline(struct lua_State * L, const char * prompt); diff --git a/src/eressea/tolua/bind_gmtool.c b/src/eressea/tolua/bind_gmtool.c index bab8c3701..fac6eccf7 100644 --- a/src/eressea/tolua/bind_gmtool.c +++ b/src/eressea/tolua/bind_gmtool.c @@ -174,4 +174,4 @@ tolua_gmtool_open(lua_State* tolua_S) tolua_endmodule(tolua_S); } tolua_endmodule(tolua_S); -} \ No newline at end of file +} diff --git a/src/eressea/tolua/bind_message.c b/src/eressea/tolua/bind_message.c index 9cc0879aa..ae4a06f14 100644 --- a/src/eressea/tolua/bind_message.c +++ b/src/eressea/tolua/bind_message.c @@ -52,7 +52,8 @@ msg_create_message(const char *type) return lmsg; } -static void +/* + static void msg_destroy_message(lua_message * msg) { if (msg->msg) msg_release(msg->msg); @@ -65,7 +66,7 @@ msg_destroy_message(lua_message * msg) } } } - +*/ int msg_set_resource(lua_message * msg, const char * param, const char * resname) { diff --git a/src/eressea/tolua/bind_region.c b/src/eressea/tolua/bind_region.c index 675adf871..a71155a63 100644 --- a/src/eressea/tolua/bind_region.c +++ b/src/eressea/tolua/bind_region.c @@ -244,6 +244,7 @@ tolua_region_open(lua_State* tolua_S) tolua_function(tolua_S, "get_resource", tolua_region_get_resource); tolua_function(tolua_S, "set_resource", tolua_region_set_resource); tolua_function(tolua_S, "get_flag", tolua_region_get_flag); + tolua_function(tolua_S, "set_flag", tolua_region_set_flag); tolua_function(tolua_S, "create", tolua_region_create); tolua_function(tolua_S, "get_key", tolua_region_getkey); diff --git a/src/eressea/tolua/bind_unit.c b/src/eressea/tolua/bind_unit.c index 67d82d554..8e3c8505d 100644 --- a/src/eressea/tolua/bind_unit.c +++ b/src/eressea/tolua/bind_unit.c @@ -46,6 +46,8 @@ without prior permission by the authors of Eressea. #include #include +#include + static int tolua_unit_get_objects(lua_State* tolua_S) { diff --git a/src/eressea/tolua/bindings.c b/src/eressea/tolua/bindings.c index d2fc9c1e0..2baa29ce1 100644 --- a/src/eressea/tolua/bindings.c +++ b/src/eressea/tolua/bindings.c @@ -280,9 +280,21 @@ tolua_dice_rand(lua_State * tolua_S) } static int -lua_addequipment(const char * eqname, const char * iname, const char * value) +tolua_addequipment(lua_State * tolua_S) { - return 0; + const char * eqname = tolua_tostring(tolua_S, 1, 0); + const char * iname = tolua_tostring(tolua_S, 2, 0); + const char * value = tolua_tostring(tolua_S, 3, 0); + int result = -1; + if (iname!=NULL) { + const struct item_type * itype = it_find(iname); + if (itype!=NULL) { + equipment_setitem(create_equipment(eqname), itype, value); + result = 0; + } + } + lua_pushnumber(tolua_S, (lua_Number)result); + return 1; } static int @@ -345,7 +357,7 @@ tolua_get_nmrs(lua_State * tolua_S) } static int -tolua_lua_equipunit(lua_State * tolua_S) +tolua_equipunit(lua_State * tolua_S) { unit * u = (unit *)tolua_tousertype(tolua_S, 1, 0); const char * eqname = tolua_tostring(tolua_S, 2, 0); @@ -709,7 +721,7 @@ tolua_eressea_open(lua_State* tolua_S) { tolua_variable(tolua_S, "name", tolua_get_alliance_name, tolua_set_alliance_name); tolua_variable(tolua_S, "id", tolua_get_alliance_id, NULL); - tolua_variable(tolua_S, "factions", tolua_get_alliance_factions, NULL); + tolua_variable(tolua_S, "factions", &tolua_get_alliance_factions, NULL); tolua_function(tolua_S, "create", tolua_alliance_create); } tolua_endmodule(tolua_S); @@ -763,7 +775,8 @@ tolua_eressea_open(lua_State* tolua_S) tolua_function(tolua_S, "get_season", tolua_get_season); tolua_function(tolua_S, "equipment_setitem", tolua_equipment_setitem); - tolua_function(tolua_S, "equip_unit", tolua_lua_equipunit); + tolua_function(tolua_S, "equip_unit", tolua_equipunit); + tolua_function(tolua_S, "add_equipment", tolua_addequipment); tolua_function(tolua_S, "atoi36", tolua_atoi36); tolua_function(tolua_S, "itoa36", tolua_itoa36);