diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-21 11:43:44 +0200 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-10-21 11:43:44 +0200 |
commit | 0b68859a8d428b2af44828c716f80e46450b1b08 (patch) | |
tree | 0f3df2b8cd4464d45ae447b42a9cc716488cb44c /crawl-ref/source | |
parent | 7974b1cb0ff0b1d4e20550a3bc731b5c7df7ed10 (diff) | |
download | crawl-ref-0b68859a8d428b2af44828c716f80e46450b1b08.tar.gz crawl-ref-0b68859a8d428b2af44828c716f80e46450b1b08.zip |
Move clua_register_metatable to cluautil.
Diffstat (limited to 'crawl-ref/source')
-rw-r--r-- | crawl-ref/source/clua.cc | 25 | ||||
-rw-r--r-- | crawl-ref/source/clua.h | 4 | ||||
-rw-r--r-- | crawl-ref/source/cluautil.cc | 23 | ||||
-rw-r--r-- | crawl-ref/source/cluautil.h | 12 |
4 files changed, 34 insertions, 30 deletions
diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc index 5c15de7389..334b481319 100644 --- a/crawl-ref/source/clua.cc +++ b/crawl-ref/source/clua.cc @@ -653,31 +653,6 @@ void CLua::remove_shutdown_listener(lua_shutdown_listener *listener) shutdown_listeners.erase(i); } -///////////////////////////////////////////////////////////////////// - -void clua_register_metatable(lua_State *ls, const char *tn, - const luaL_reg *lr, - int (*gcfn)(lua_State *ls)) -{ - lua_stack_cleaner clean(ls); - luaL_newmetatable(ls, tn); - lua_pushstring(ls, "__index"); - lua_pushvalue(ls, -2); - lua_settable(ls, -3); - - if (gcfn) - { - lua_pushstring(ls, "__gc"); - lua_pushcfunction(ls, gcfn); - lua_settable(ls, -3); - } - - if (lr) - { - luaL_openlib(ls, NULL, lr, 0); - } -} - //////////////////////////////////////////////////////////////////////// // lua_text_pattern diff --git a/crawl-ref/source/clua.h b/crawl-ref/source/clua.h index ed35813dd5..daca3922aa 100644 --- a/crawl-ref/source/clua.h +++ b/crawl-ref/source/clua.h @@ -298,10 +298,6 @@ template <class T> T *clua_new_userdata( return static_cast<T*>( udata ); } -void clua_register_metatable(lua_State *ls, const char *tn, - const luaL_reg *lr, - int (*gcfn)(lua_State *ls) = NULL); - void print_clua_stack(); #endif diff --git a/crawl-ref/source/cluautil.cc b/crawl-ref/source/cluautil.cc index 13f5ab7267..fe0ba1cd93 100644 --- a/crawl-ref/source/cluautil.cc +++ b/crawl-ref/source/cluautil.cc @@ -75,3 +75,26 @@ void luaopen_setmeta(lua_State *ls, lua_pushvalue(ls, -2); lua_settable(ls, -3); } + +void clua_register_metatable(lua_State *ls, const char *tn, + const luaL_reg *lr, + int (*gcfn)(lua_State *ls)) +{ + lua_stack_cleaner clean(ls); + luaL_newmetatable(ls, tn); + lua_pushstring(ls, "__index"); + lua_pushvalue(ls, -2); + lua_settable(ls, -3); + + if (gcfn) + { + lua_pushstring(ls, "__gc"); + lua_pushcfunction(ls, gcfn); + lua_settable(ls, -3); + } + + if (lr) + { + luaL_openlib(ls, NULL, lr, 0); + } +} diff --git a/crawl-ref/source/cluautil.h b/crawl-ref/source/cluautil.h index 1af4d76485..02e5180d7c 100644 --- a/crawl-ref/source/cluautil.h +++ b/crawl-ref/source/cluautil.h @@ -6,21 +6,31 @@ #ifndef CLUAUTIL_H #define CLUAUTIL_H +extern "C" { +#include <lua.h> +#include <lauxlib.h> +#include <lualib.h> +} + /* * Function definitions. */ #define LUAFN(name) static int name(lua_State *ls) +// FIXME: remove one of these. void luaopen_setmeta(lua_State *ls, const char *global, const luaL_reg *lua_lib, const char *meta); +void clua_register_metatable(lua_State *ls, const char *tn, + const luaL_reg *lr, + int (*gcfn)(lua_State *ls) = NULL); + /* * Passing objects from and to Lua. */ -struct lua_State; struct activity_interrupt_data; int push_activity_interrupt(lua_State *ls, activity_interrupt_data *t); |