forked from github/server
lua for the gmtool
This commit is contained in:
parent
b74a0b6b50
commit
4316903e9a
|
@ -7,6 +7,9 @@ SubDirHdrs $(SUBDIR)/../common/util ;
|
|||
SubDirHdrs $(SUBDIR)/../common ;
|
||||
SubDirHdrs $(SUBDIR)/.. ;
|
||||
|
||||
UsingLua ;
|
||||
UsingLuabind ;
|
||||
|
||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) curses ] ;
|
||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) lua ] ;
|
||||
SubDirC++Flags -DHAVE_LUA ;
|
||||
|
@ -39,22 +42,17 @@ LUASERVER_SOURCES =
|
|||
|
||||
GMTOOL_SOURCES =
|
||||
<curses>listbox.c
|
||||
gmtool.c
|
||||
console.c
|
||||
editing.c
|
||||
gmmain.cpp
|
||||
gmtool.c
|
||||
;
|
||||
|
||||
# the curses-based GM tool
|
||||
Main $(GMTOOL) : $(GMTOOL_SOURCES) ;
|
||||
LinkLibraries $(GMTOOL) :
|
||||
kernel modules items attributes spells races triggers util ;
|
||||
libxml2 $(GMTOOL) ;
|
||||
LINKLIBS on $(GMTOOL) += -L$(LUABIND_ROOT)/lib -lm -lncurses ;
|
||||
|
||||
# old eressea server. use only for testing.
|
||||
LinkLibraries $(SERVER) :
|
||||
gamecode kernel items modules attributes spells races triggers util ;
|
||||
libxml2 $(SERVER) ;
|
||||
LINKLIBS on $(SERVER) += -L$(LUABIND_ROOT)/lib -lm ;
|
||||
LINKLIBS on $(SERVER) += -lm ;
|
||||
Main $(SERVER) : $(SERVER_SOURCES) ;
|
||||
|
||||
# eressea-server with lua scripting
|
||||
|
@ -63,7 +61,12 @@ LinkLibraries $(LUASERVER) :
|
|||
luabind $(LUASERVER) ;
|
||||
libxml2 $(LUASERVER) ;
|
||||
LINKLIBS on $(LUASERVER) += -lm -ldl -lstdc++ ;
|
||||
UsingLua ;
|
||||
UsingLuabind ;
|
||||
Main $(LUASERVER) : $(LUASERVER_SOURCES) ;
|
||||
|
||||
# the curses-based GM tool (now with luabind)
|
||||
LinkLibraries $(GMTOOL) :
|
||||
kernel modules items attributes spells races triggers util ;
|
||||
luabind $(GMTOOL) ;
|
||||
libxml2 $(GMTOOL) ;
|
||||
LINKLIBS on $(GMTOOL) += -lm -lncurses ;
|
||||
Main $(GMTOOL) : $(GMTOOL_SOURCES) ;
|
||||
|
|
|
@ -16,9 +16,6 @@
|
|||
** this macro defines a function to show the prompt and reads the
|
||||
** next line for manual input
|
||||
*/
|
||||
#ifndef lua_readline
|
||||
#define lua_readline(L,prompt) readline(L,prompt)
|
||||
|
||||
/* maximum length of an input line */
|
||||
#ifndef MAXINPUT
|
||||
#define MAXINPUT 512
|
||||
|
@ -39,7 +36,8 @@ readline(lua_State *l, const char *prompt)
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int (*lua_readline)(lua_State *l, const char *prompt) = readline;
|
||||
|
||||
#ifndef PROMPT
|
||||
#define PROMPT "E> "
|
||||
|
@ -178,3 +176,22 @@ lua_console(lua_State * L)
|
|||
fputs("\n", stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
lua_do(lua_State * L)
|
||||
{
|
||||
int status = load_string(L);
|
||||
if (status != -1) {
|
||||
if (status == 0) status = lcall(L, 0, 0);
|
||||
l_report(L, status);
|
||||
if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
|
||||
lua_getglobal(L, "print");
|
||||
lua_insert(L, 1);
|
||||
if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
|
||||
l_message(NULL, lua_pushfstring(L, "error calling `print' (%s)",
|
||||
lua_tostring(L, -1)));
|
||||
}
|
||||
}
|
||||
lua_settop(L, 0); /* clear stack */
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ extern "C" {
|
|||
#include <lua50/lua.h>
|
||||
|
||||
extern int lua_console(lua_State * L);
|
||||
extern int lua_do(lua_State * L);
|
||||
extern int (*lua_readline)(lua_State *l, const char *prompt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/* vi: set ts=2:
|
||||
* +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
* | | Enno Rehling <enno@eressea.de>
|
||||
* | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
* | (c) 1998 - 2006 |
|
||||
* | | This program may not be used, modified or distributed
|
||||
* +-------------------+ without prior permission by the authors of Eressea.
|
||||
*
|
||||
*/
|
||||
|
||||
/* wenn config.h nicht vor curses included wird, kompiliert es unter windows nicht */
|
||||
#include <config.h>
|
||||
#include <eressea.h>
|
||||
|
||||
#include "console.h"
|
||||
#include "gmtool.h"
|
||||
|
||||
/* lua includes */
|
||||
#include "lua/bindings.h"
|
||||
#include "lua/script.h"
|
||||
#include <boost/version.hpp>
|
||||
#include <lua.hpp>
|
||||
#include <luabind/luabind.hpp>
|
||||
|
||||
static lua_State *
|
||||
lua_init(void)
|
||||
{
|
||||
lua_State * L = lua_open();
|
||||
luaopen_base(L);
|
||||
luaopen_math(L);
|
||||
luaopen_string(L);
|
||||
luaopen_io(L);
|
||||
luaopen_table(L);
|
||||
#if 0
|
||||
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);
|
||||
#endif
|
||||
lua_readline = curses_readline;
|
||||
return L;
|
||||
}
|
||||
|
||||
static void
|
||||
lua_done(lua_State * L)
|
||||
{
|
||||
#if 0
|
||||
reset_scripts();
|
||||
#endif
|
||||
lua_close(L);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
lua_State* luaState = lua_init();
|
||||
global.vm_state = luaState;
|
||||
|
||||
int result = gmmain(argc, argv);
|
||||
lua_done(luaState);
|
||||
|
||||
return result;
|
||||
}
|
|
@ -14,7 +14,9 @@
|
|||
#include <eressea.h>
|
||||
|
||||
#include "gmtool.h"
|
||||
#include "gmtool_structs.h"
|
||||
#include "editing.h"
|
||||
#include "console.h"
|
||||
#include "curses/listbox.h"
|
||||
|
||||
#include <modules/xmas.h>
|
||||
|
@ -73,6 +75,8 @@ static int force_color = 0;
|
|||
#define IFL_FACTIONS (1<<2)
|
||||
#define IFL_BUILDINGS (1<<3)
|
||||
|
||||
static WINDOW * hstatus;
|
||||
|
||||
static int
|
||||
usage(const char * prog, const char * arg)
|
||||
{
|
||||
|
@ -221,7 +225,7 @@ game_done(void)
|
|||
static void
|
||||
init_curses(void)
|
||||
{
|
||||
int fg, bg;
|
||||
short fg, bg;
|
||||
initscr();
|
||||
|
||||
if (has_colors() || force_color) {
|
||||
|
@ -968,6 +972,11 @@ handlekey(state * st, int c)
|
|||
}
|
||||
} while (c==0);
|
||||
break;
|
||||
case 'L':
|
||||
if (global.vm_state) {
|
||||
lua_do((lua_State*)global.vm_state);
|
||||
}
|
||||
break;
|
||||
case 'H':
|
||||
select_regions(st, MODE_HIGHLIGHT);
|
||||
break;
|
||||
|
@ -1165,6 +1174,8 @@ run_mapper(void)
|
|||
init_view(&st.display, hwinmap);
|
||||
coor2point(&st.display.topleft, &tl);
|
||||
|
||||
hstatus = st.wnd_status->handle; /* the lua console needs this */
|
||||
|
||||
while (!g_quit) {
|
||||
int c;
|
||||
point p;
|
||||
|
@ -1223,8 +1234,22 @@ run_mapper(void)
|
|||
endwin();
|
||||
}
|
||||
|
||||
#define MAXINPUT 512
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
curses_readline(lua_State * L, const char * prompt)
|
||||
{
|
||||
static char buffer[MAXINPUT];
|
||||
askstring(hstatus, prompt, buffer, MAXINPUT);
|
||||
if (buffer[0]==0) {
|
||||
return 0; /* read fails */
|
||||
} else {
|
||||
lua_pushstring(L, buffer);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
gmmain(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
char * lc_ctype;
|
||||
|
@ -1245,7 +1270,6 @@ main(int argc, char *argv[])
|
|||
if (i!=0) return i;
|
||||
game_init();
|
||||
|
||||
|
||||
if (turn>first_turn) {
|
||||
char datafile[12];
|
||||
sprintf(datafile, "%u", turn);
|
||||
|
@ -1267,3 +1291,11 @@ main(int argc, char *argv[])
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef USE_C_MAIN
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
return gmmain(argc, argv);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -8,70 +8,19 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/* types imported from eressea: */
|
||||
struct region;
|
||||
#ifndef H_GMTOOL
|
||||
#define H_GMTOOL
|
||||
|
||||
typedef struct extent {
|
||||
/* Ein Vektor */
|
||||
int width, height;
|
||||
} extent;
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct point {
|
||||
/* Eine Koordinate in einer Ascii-Karte */
|
||||
int x, y;
|
||||
} point;
|
||||
extern int gmmain(int argc, char *argv[]);
|
||||
extern int curses_readline(struct lua_State * L, const char * prompt);
|
||||
|
||||
typedef struct coordinate {
|
||||
/* Eine Koordinate in der Welt */
|
||||
int x, y, p;
|
||||
} coordinate;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct map_region {
|
||||
struct region * r;
|
||||
coordinate coord;
|
||||
} map_region;
|
||||
|
||||
typedef struct view {
|
||||
struct map_region * regions;
|
||||
int plane;
|
||||
coordinate topleft; /* upper left corner in map. */
|
||||
extent extent; /* dimensions. */
|
||||
} view;
|
||||
|
||||
typedef struct tag {
|
||||
coordinate coord;
|
||||
struct tag * nexthash;
|
||||
} tag;
|
||||
|
||||
#define MAXTHASH 512
|
||||
|
||||
typedef struct selection {
|
||||
tag * tags[MAXTHASH];
|
||||
} selection;
|
||||
|
||||
typedef struct state {
|
||||
coordinate cursor;
|
||||
selection * selected;
|
||||
struct state * undo;
|
||||
struct faction * topf;
|
||||
view display;
|
||||
int modified;
|
||||
unsigned int info_flags;
|
||||
struct window * wnd_info;
|
||||
struct window * wnd_map;
|
||||
struct window * wnd_status;
|
||||
} state;
|
||||
|
||||
typedef struct window {
|
||||
boolean (*handlekey)(struct window * win, struct state * st, int key);
|
||||
void (*paint)(struct window * win, const struct state * st);
|
||||
|
||||
WINDOW * handle;
|
||||
struct window * next;
|
||||
struct window * prev;
|
||||
boolean initialized;
|
||||
int update;
|
||||
} window;
|
||||
|
||||
#define TWIDTH 2 /* width of tile */
|
||||
#define THEIGHT 1 /* height of tile */
|
||||
#endif
|
||||
|
|
|
@ -91,7 +91,6 @@
|
|||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="4"
|
||||
BufferSecurityCheck="TRUE"
|
||||
DisableLanguageExtensions="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
PrecompiledHeaderFile=".\Debug/gmtool.pch"
|
||||
|
@ -108,7 +107,7 @@
|
|||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/MACHINE:I386"
|
||||
AdditionalDependencies="curses.lib libxml2.lib"
|
||||
AdditionalDependencies="lua50.lib curses.lib libxml2.lib"
|
||||
OutputFile=".\Debug/gmtool.exe"
|
||||
LinkIncremental="2"
|
||||
SuppressStartupBanner="TRUE"
|
||||
|
@ -216,13 +215,22 @@
|
|||
<File
|
||||
RelativePath=".\gmtool.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\gmtool_structs.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\curses\listbox.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\console.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\editing.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\gmmain.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\gmtool.c">
|
||||
</File>
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
/* vi: set ts=2:
|
||||
* +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
* | | Enno Rehling <enno@eressea.de>
|
||||
* | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
* | (c) 1998 - 2006 |
|
||||
* | | This program may not be used, modified or distributed
|
||||
* +-------------------+ without prior permission by the authors of Eressea.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef H_GMTOOL_STRUCTS
|
||||
#define H_GMTOOL_STRUCTS
|
||||
|
||||
/* types imported from eressea: */
|
||||
struct region;
|
||||
|
||||
typedef struct extent {
|
||||
/* Ein Vektor */
|
||||
int width, height;
|
||||
} extent;
|
||||
|
||||
typedef struct point {
|
||||
/* Eine Koordinate in einer Ascii-Karte */
|
||||
int x, y;
|
||||
} point;
|
||||
|
||||
typedef struct coordinate {
|
||||
/* Eine Koordinate in der Welt */
|
||||
int x, y, p;
|
||||
} coordinate;
|
||||
|
||||
typedef struct map_region {
|
||||
struct region * r;
|
||||
coordinate coord;
|
||||
} map_region;
|
||||
|
||||
typedef struct view {
|
||||
struct map_region * regions;
|
||||
int plane;
|
||||
coordinate topleft; /* upper left corner in map. */
|
||||
extent extent; /* dimensions. */
|
||||
} view;
|
||||
|
||||
typedef struct tag {
|
||||
coordinate coord;
|
||||
struct tag * nexthash;
|
||||
} tag;
|
||||
|
||||
#define MAXTHASH 512
|
||||
|
||||
typedef struct selection {
|
||||
tag * tags[MAXTHASH];
|
||||
} selection;
|
||||
|
||||
typedef struct state {
|
||||
coordinate cursor;
|
||||
selection * selected;
|
||||
struct state * undo;
|
||||
struct faction * topf;
|
||||
view display;
|
||||
int modified;
|
||||
unsigned int info_flags;
|
||||
struct window * wnd_info;
|
||||
struct window * wnd_map;
|
||||
struct window * wnd_status;
|
||||
} state;
|
||||
|
||||
typedef struct window {
|
||||
boolean (*handlekey)(struct window * win, struct state * st, int key);
|
||||
void (*paint)(struct window * win, const struct state * st);
|
||||
|
||||
WINDOW * handle;
|
||||
struct window * next;
|
||||
struct window * prev;
|
||||
boolean initialized;
|
||||
int update;
|
||||
} window;
|
||||
|
||||
#define TWIDTH 2 /* width of tile */
|
||||
#define THEIGHT 1 /* height of tile */
|
||||
|
||||
#endif
|
|
@ -286,7 +286,7 @@ readshortpwds()
|
|||
}
|
||||
#endif
|
||||
|
||||
lua_State *
|
||||
static lua_State *
|
||||
lua_init(void)
|
||||
{
|
||||
lua_State * luaState = lua_open();
|
||||
|
@ -312,7 +312,7 @@ lua_init(void)
|
|||
return luaState;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
lua_done(lua_State * luaState)
|
||||
{
|
||||
reset_scripts();
|
||||
|
|
Loading…
Reference in New Issue