Integrated the editor into the main executable (which means it now requires curses). Should make a #define to disable compilation.

This commit is contained in:
Enno Rehling 2008-04-19 16:12:13 +00:00
parent 6f9f857a83
commit 6739d5ff7e
23 changed files with 90 additions and 94 deletions

View File

@ -18,8 +18,6 @@ SubDirC++Flags -DHAVE_LUA ;
SubDirHdrs $(XMLHDRS) ;
LUASERVER = eressea-lua ;
SERVER = eressea ;
GMTOOL = gmtool ;
SERVER_SOURCES = main.c korrektur.c ;
@ -42,46 +40,25 @@ Library luabindings : $(SHARED_BINDINGS) ;
LUASERVER_SOURCES =
<common!iniparser>iniparser.c
<common!iniparser>iniparser.c
<lua>gm.cpp
<lua>script.cpp
<lua>gamecode.cpp
<curses>listbox.c
server.cpp
korrektur.c
console.c
;
GMTOOL_SOURCES =
<common!iniparser>iniparser.c
<lua>gm.cpp
<curses>listbox.c
console.c
editing.c
gmmain.cpp
gmtool.c
;
# old eressea server. use only for testing.
LinkLibraries $(SERVER) :
gamecode items spells kernel modules attributes races triggers util ;
libxml2 $(SERVER) ;
LINKLIBS on $(SERVER) += -lm ;
# build disabled:
# Main $(SERVER) : $(SERVER_SOURCES) ;
# eressea-server with lua scripting
LinkLibraries $(LUASERVER) :
luabindings gamecode items spells kernel modules attributes races triggers util ;
luabind $(LUASERVER) ;
libxml2 $(LUASERVER) ;
LINKLIBS on $(LUASERVER) += -lm -ldl -lstdc++ ;
LINKLIBS on $(LUASERVER) += -lm -ldl -lstdc++ -lncurses ;
if $(DEBUG) = 1 {
LINKLIBS on $(LUASERVER) += -lmcheck ;
}
Main $(LUASERVER) : $(LUASERVER_SOURCES) ;
# the curses-based GM tool (now with luabind)
LinkLibraries $(GMTOOL) :
luabindings items spells kernel modules attributes races triggers util ;
luabind $(GMTOOL) ;
libxml2 $(GMTOOL) ;
LINKLIBS on $(GMTOOL) += -lm -lncurses -ldl -lstdc++ ;
Main $(GMTOOL) : $(GMTOOL_SOURCES) ;

View File

@ -21,7 +21,7 @@
#endif
static int
readline(lua_State *l, const char *prompt)
stdin_readline(lua_State *l, const char *prompt)
{
static char buffer[MAXINPUT];
if (prompt) {
@ -36,7 +36,17 @@ readline(lua_State *l, const char *prompt)
}
}
int (*lua_readline)(lua_State *l, const char *prompt) = readline;
static int (*lua_readline)(lua_State *l, const char *prompt) = stdin_readline;
void
set_readline(readline foo)
{
if (foo) {
lua_readline = foo;
} else {
lua_readline = stdin_readline;
}
}
#ifndef PROMPT
#define PROMPT "E> "
@ -127,31 +137,37 @@ lstop(lua_State *l, lua_Debug *ar)
luaL_error(l, "interrupted!");
}
static lua_State * global_state = NULL;
/* BAD hack, all this action stuff. */
#define STATESTACK_MAX 16
static lua_State * state_stack[STATESTACK_MAX];
int state_stack_top = -1;
static void
laction(int i)
{
signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
terminate process (default action) */
assert(global_state!=NULL);
lua_sethook(global_state, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
assert(state_stack_top>=0 && state_stack_top<STATESTACK_MAX);
lua_sethook(state_stack[state_stack_top], lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
}
static int
lcall(lua_State * L, int narg, int clear)
{
int status;
int status, pop_state = state_stack_top;
int base = lua_gettop(L) - narg; /* function index */
lua_pushliteral(L, "_TRACEBACK");
lua_rawget(L, LUA_GLOBALSINDEX); /* get traceback function */
lua_insert(L, base); /* put it under chunk and args */
assert(global_state==NULL);
global_state = L; /* baaaad hack */
if (state_stack_top<0 || L != state_stack[state_stack_top]) {
assert(state_stack_top+1<STATESTACK_MAX);
state_stack[++state_stack_top] = L;
}
signal(SIGINT, laction);
status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
signal(SIGINT, SIG_DFL);
assert(global_state==L);
global_state=NULL;
state_stack_top = pop_state;
lua_remove(L, base); /* remove traceback function */
return status;
}

View File

@ -14,7 +14,9 @@ extern "C" {
extern int lua_console(lua_State * L);
extern int lua_do(lua_State * L);
extern int (*lua_readline)(lua_State *l, const char *prompt);
typedef int (*readline)(struct lua_State *, const char *);
extern void set_readline(readline foo);
#ifdef __cplusplus
}

View File

@ -9,7 +9,7 @@
*/
#include <config.h>
#include <eressea.h>
#include <kernel/eressea.h>
#include "editing.h"
#include <kernel/region.h>

View File

@ -11,7 +11,7 @@
/* wenn config.h nicht vor curses included wird, kompiliert es unter windows nicht */
#include <config.h>
#include <curses.h>
#include <eressea.h>
#include <kernel/eressea.h>
#include "gmtool.h"
#include "gmtool_structs.h"
@ -1176,19 +1176,23 @@ update_view(view * vi)
}
}
static void
void
run_mapper(void)
{
WINDOW * hwinstatus;
WINDOW * hwininfo;
WINDOW * hwinmap;
int width, height, x, y;
int split = 20;
int split = 20, old_flags = log_flags;
state st;
point tl;
log_flags &= ~(LOG_CPERROR|LOG_CPWARNING);
init_curses();
curs_set(1);
set_readline(curses_readline);
getbegyx(stdscr, x, y);
width = getmaxx(stdscr);
height = getmaxy(stdscr);
@ -1275,8 +1279,10 @@ run_mapper(void)
draw_cursor(st.wnd_map->handle, st.selected, vi, &st.cursor, 0);
handlekey(&st, c);
}
set_readline(NULL);
curs_set(1);
endwin();
log_flags = old_flags;
current_state = NULL;
}
@ -1315,6 +1321,7 @@ load_inifile(const char * filename)
inifile = d;
}
#ifdef USE_C_MAIN
int
gmmain(int argc, char *argv[])
{
@ -1364,7 +1371,6 @@ gmmain(int argc, char *argv[])
return 0;
}
#ifdef USE_C_MAIN
int
main(int argc, char *argv[])
{

View File

@ -21,6 +21,7 @@ extern "C" {
extern void highlight_region(struct region *r);
extern void select_coordinate(struct selection * selected, int x, int y);
extern void run_mapper(void);
#ifdef __cplusplus
}

View File

@ -19,7 +19,7 @@
*/
#include <config.h>
#include <types.h>
#include <kernel/types.h>
/* misc includes */
#include <attributes/key.h>
@ -343,7 +343,7 @@ fix_demands(void)
return 0;
}
#include "group.h"
#include <kernel/group.h>
static void
fix_allies(void)
{

View File

@ -1,5 +1,5 @@
#include <config.h>
#include <eressea.h>
#include <kernel/eressea.h>
#include "list.h"

View File

@ -1,13 +1,13 @@
#include <config.h>
#include <eressea.h>
#include <kernel/eressea.h>
#include "list.h"
#include "objects.h"
#include "bindings.h"
// kernel includes
#include <building.h>
#include <region.h>
#include <unit.h>
#include <kernel/building.h>
#include <kernel/region.h>
#include <kernel/unit.h>
// lua includes
#pragma warning (push)

View File

@ -1,5 +1,5 @@
#include <config.h>
#include <eressea.h>
#include <kernel/eressea.h>
#include "bindings.h"

View File

@ -1,5 +1,5 @@
#include <config.h>
#include <eressea.h>
#include <kernel/eressea.h>
#include "event.h"
// kernel includes

View File

@ -1,5 +1,5 @@
#include <config.h>
#include <eressea.h>
#include <kernel/eressea.h>
#include "list.h"
#include "objects.h"

View File

@ -1,5 +1,5 @@
#include <config.h>
#include <eressea.h>
#include <kernel/eressea.h>
#include "script.h"
#include "../korrektur.h"
@ -125,7 +125,7 @@ static int
read_game(const char * filename)
{
int rv = readgame(filename, false);
printf(" - Korrekturen Runde %d\n", turn);
log_printf(" - Korrekturen Runde %d\n", turn);
korrektur();
return rv;
}

View File

@ -1,5 +1,5 @@
#include <config.h>
#include <eressea.h>
#include <kernel/eressea.h>
#include "bindings.h"
#include "list.h"
@ -77,6 +77,7 @@ void
bind_gmtool(lua_State * L)
{
module(L, "gmtool")[
def("editor", &run_mapper),
def("selection", &selected_regions, return_stl_iterator),
def("cursor", &current_region),
def("highlight", &highlight_region),

View File

@ -1,5 +1,5 @@
#include <config.h>
#include <eressea.h>
#include <kernel/eressea.h>
#include "bindings.h"

View File

@ -1,10 +1,10 @@
#include <config.h>
#include <eressea.h>
#include "message.h"
#include <kernel/eressea.h>
// kernel includes
#include <kernel/faction.h>
#include <kernel/item.h>
#include <kernel/message.h>
#include <kernel/region.h>
#include <kernel/unit.h>

View File

@ -1,5 +1,5 @@
#include <config.h>
#include <eressea.h>
#include <kernel/eressea.h>
#include "objects.h"
#include <kernel/region.h>

View File

@ -1,5 +1,5 @@
#include <config.h>
#include <eressea.h>
#include <kernel/eressea.h>
#include "list.h"
#include "objects.h"

View File

@ -13,7 +13,7 @@
#include <config.h>
#include <boost/version.hpp>
#include <lua.hpp>
#include "eressea.h"
#include <kernel/eressea.h>
#include "script.h"
#include "bindings.h"

View File

@ -1,5 +1,5 @@
#include <config.h>
#include <eressea.h>
#include <kernel/eressea.h>
#include "objects.h"
// kernel includes

View File

@ -1,5 +1,5 @@
#include <config.h>
#include <eressea.h>
#include <kernel/eressea.h>
#include "list.h"
// kernel includes

View File

@ -1,5 +1,5 @@
#include <config.h>
#include <eressea.h>
#include <kernel/eressea.h>
#include "list.h"
#include "objects.h"
#include "bindings.h"

View File

@ -26,7 +26,7 @@
/* config includes */
#include <config.h>
#include <eressea.h>
#include <kernel/eressea.h>
#include "console.h"
@ -251,8 +251,6 @@ game_init(void)
init_data(xmlfile);
init_locales();
/* init_resources(); must be done inside the xml-read, because requirements use items */
init_archetypes();
init_attributes();
init_itemtypes();
@ -290,32 +288,27 @@ openlibs(lua_State * L)
static lua_State *
lua_init(void)
{
lua_State * luaState = lua_open();
/*
luaopen_base(luaState);
luaopen_math(luaState);
luaopen_string(luaState);
luaopen_io(luaState);
luaopen_table(luaState);
luaL_openlibs(luaState);
*/
openlibs(luaState);
luabind::open(luaState);
bind_objects(luaState);
bind_eressea(luaState);
bind_script(luaState);
bind_spell(luaState);
bind_alliance(luaState);
bind_region(luaState);
bind_item(luaState);
bind_faction(luaState);
bind_unit(luaState);
bind_ship(luaState);
bind_building(luaState);
bind_event(luaState);
bind_message(luaState);
bind_gamecode(luaState);
return luaState;
lua_State * L = lua_open();
openlibs(L);
luabind::open(L);
bind_objects(L);
bind_eressea(L);
bind_script(L);
bind_spell(L);
bind_alliance(L);
bind_region(L);
bind_item(L);
bind_faction(L);
bind_unit(L);
bind_ship(L);
bind_building(L);
bind_event(L);
bind_message(L);
bind_gamecode(L);
bind_gmtool(L);
return L;
}
static void