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/cluautil.cc | |
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/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 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); + } +} |