diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-21 12:25:48 +0200 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-10-21 12:25:48 +0200 |
commit | df9d0d88a17ed81f394e76d336657e5a180c0c36 (patch) | |
tree | a988abc4ae6fa4cbfd434e4dfc9e98c2f74e3b76 /crawl-ref/source/cluautil.cc | |
parent | 5b65cad7433ded2e76bd162c21709133f7cfc439 (diff) | |
download | crawl-ref-df9d0d88a17ed81f394e76d336657e5a180c0c36.tar.gz crawl-ref-df9d0d88a17ed81f394e76d336657e5a180c0c36.zip |
Move more utility code from dlua to cluautil.
Diffstat (limited to 'crawl-ref/source/cluautil.cc')
-rw-r--r-- | crawl-ref/source/cluautil.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/crawl-ref/source/cluautil.cc b/crawl-ref/source/cluautil.cc index fe0ba1cd93..2a9cfe47bb 100644 --- a/crawl-ref/source/cluautil.cc +++ b/crawl-ref/source/cluautil.cc @@ -98,3 +98,26 @@ void clua_register_metatable(lua_State *ls, const char *tn, luaL_openlib(ls, NULL, lr, 0); } } + + +template <typename list, typename lpush> +static int dlua_gentable(lua_State *ls, const list &strings, lpush push) +{ + lua_newtable(ls); + for (int i = 0, size = strings.size(); i < size; ++i) + { + push(ls, strings[i]); + lua_rawseti(ls, -2, i + 1); + } + return (1); +} + +inline static void dlua_pushcxxstring(lua_State *ls, const std::string &s) +{ + lua_pushstring(ls, s.c_str()); +} + +int dlua_stringtable(lua_State *ls, const std::vector<std::string> &s) +{ + return dlua_gentable(ls, s, dlua_pushcxxstring); +} |