mirror of
https://github.com/lunarmodules/luafilesystem.git
synced 2026-07-25 05:03:07 +00:00
Simplify and clarify metatable creation functions.
This commit is contained in:
22
src/lfs.c
22
src/lfs.c
@@ -534,19 +534,18 @@ static int dir_iter_factory (lua_State *L) {
|
|||||||
*/
|
*/
|
||||||
static int dir_create_meta (lua_State *L) {
|
static int dir_create_meta (lua_State *L) {
|
||||||
luaL_newmetatable (L, DIR_METATABLE);
|
luaL_newmetatable (L, DIR_METATABLE);
|
||||||
/* set its __gc field */
|
|
||||||
lua_pushstring (L, "__index");
|
/* Method table */
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
lua_pushstring (L, "next");
|
|
||||||
lua_pushcfunction (L, dir_iter);
|
lua_pushcfunction (L, dir_iter);
|
||||||
lua_settable(L, -3);
|
lua_setfield(L, -2, "next");
|
||||||
lua_pushstring (L, "close");
|
|
||||||
lua_pushcfunction (L, dir_close);
|
lua_pushcfunction (L, dir_close);
|
||||||
lua_settable(L, -3);
|
lua_setfield(L, -2, "close");
|
||||||
lua_settable (L, -3);
|
|
||||||
lua_pushstring (L, "__gc");
|
/* Metamethods */
|
||||||
|
lua_setfield(L, -2, "__index");
|
||||||
lua_pushcfunction (L, dir_close);
|
lua_pushcfunction (L, dir_close);
|
||||||
lua_settable (L, -3);
|
lua_setfield (L, -2, "__gc");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,10 +554,13 @@ static int dir_create_meta (lua_State *L) {
|
|||||||
*/
|
*/
|
||||||
static int lock_create_meta (lua_State *L) {
|
static int lock_create_meta (lua_State *L) {
|
||||||
luaL_newmetatable (L, LOCK_METATABLE);
|
luaL_newmetatable (L, LOCK_METATABLE);
|
||||||
/* set its __gc field */
|
|
||||||
|
/* Method table */
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
lua_pushcfunction(L, lfs_unlock_dir);
|
lua_pushcfunction(L, lfs_unlock_dir);
|
||||||
lua_setfield(L, -2, "free");
|
lua_setfield(L, -2, "free");
|
||||||
|
|
||||||
|
/* Metamethods */
|
||||||
lua_setfield(L, -2, "__index");
|
lua_setfield(L, -2, "__index");
|
||||||
lua_pushcfunction(L, lfs_unlock_dir);
|
lua_pushcfunction(L, lfs_unlock_dir);
|
||||||
lua_setfield(L, -2, "__gc");
|
lua_setfield(L, -2, "__gc");
|
||||||
|
|||||||
Reference in New Issue
Block a user