diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-27 19:16:50 +0100 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-10-27 19:16:50 +0100 |
commit | 5c2086ac6f8e8b53bfa9655cf02dca03c41850ce (patch) | |
tree | adedbe0a773dc8e2113fdfad92d58c2f455c33e0 /crawl-ref/source | |
parent | 4c3e4246769fecd226e08304a01d581e19a197d3 (diff) | |
download | crawl-ref-5c2086ac6f8e8b53bfa9655cf02dca03c41850ce.tar.gz crawl-ref-5c2086ac6f8e8b53bfa9655cf02dca03c41850ce.zip |
Start of monster_info lua binding.
Diffstat (limited to 'crawl-ref/source')
-rw-r--r-- | crawl-ref/source/l_libs.h | 1 | ||||
-rw-r--r-- | crawl-ref/source/l_moninf.cc | 57 | ||||
-rw-r--r-- | crawl-ref/source/makefile.obj | 1 |
3 files changed, 59 insertions, 0 deletions
diff --git a/crawl-ref/source/l_libs.h b/crawl-ref/source/l_libs.h index 736545caab..115c1928ac 100644 --- a/crawl-ref/source/l_libs.h +++ b/crawl-ref/source/l_libs.h @@ -17,6 +17,7 @@ void cluaopen_file(lua_State *ls); void cluaopen_food(lua_State *ls); void cluaopen_item(lua_State *ls); void cluaopen_kills(lua_State *ls); // defined in kills.cc +void cluaopen_moninf(lua_State *ls); void cluaopen_options(lua_State *ls); void cluaopen_you(lua_State *ls); diff --git a/crawl-ref/source/l_moninf.cc b/crawl-ref/source/l_moninf.cc new file mode 100644 index 0000000000..db21ca0074 --- /dev/null +++ b/crawl-ref/source/l_moninf.cc @@ -0,0 +1,57 @@ +/* + * File: l_moninf.cc + * Summary: User-accessible monster info. + */ + +#include "AppHdr.h" + +#include "l_libs.h" + +#include "cluautil.h" +#include "mon-info.h" + +#define MONINF_METATABLE "monster.info" + +void lua_push_moninf(lua_State *ls, monster_info *mi) +{ + monster_info **miref = + clua_new_userdata<monster_info *>(ls, MONINF_METATABLE); + *miref = mi; +} + +#define MONINF(ls, n, var) \ + monster_info *var = *(monster_info **) \ + luaL_checkudata(ls, n, MONINF_METATABLE) + +#define MIRET1(type, field) \ + static int moninf_get_##field(lua_State *ls) \ + { \ + MONINF(ls, 1, mi); \ + lua_push##type(ls, mi->m_##field); \ + return (1); \ + } + +#define MIREG(field) { #field, moninf_get_##field } + +MIRET1(number, damage_level) + +LUAFN(moninf_get_damage_desc) +{ + MONINF(ls, 1, mi); + lua_pushstring(ls, mi->m_damage_desc.c_str()); + return (1); +} + +static const struct luaL_reg moninf_lib[] = +{ + MIREG(damage_level), + MIREG(damage_desc), + + { NULL, NULL } +}; + +void cluaopen_moninf(lua_State *ls) +{ + clua_register_metatable(ls, MONINF_METATABLE, moninf_lib, + lua_object_gc<monster_info>); +} diff --git a/crawl-ref/source/makefile.obj b/crawl-ref/source/makefile.obj index c950133deb..2e32e73cfe 100644 --- a/crawl-ref/source/makefile.obj +++ b/crawl-ref/source/makefile.obj @@ -62,6 +62,7 @@ l_item.o \ l_los.o \ l_mapgrd.o \ l_mapmrk.o \ +l_moninf.o \ l_mons.o \ l_option.o \ l_you.o \ |