diff options
| author | Reuben Thomas <rrt@sc3d.org> | 2011-06-09 20:35:12 +0100 |
|---|---|---|
| committer | Reuben Thomas <rrt@sc3d.org> | 2011-06-09 20:35:12 +0100 |
| commit | 83faa7e05d288dcb543109509e17de25110203ef (patch) | |
| tree | 4d761ac2e47869a23e1958e144e1dfe4a4818479 /src | |
| parent | 3cea6c6e9612ca2b04b4742c04721d24f4b316be (diff) | |
| download | luafilesystem-83faa7e05d288dcb543109509e17de25110203ef.tar.gz luafilesystem-83faa7e05d288dcb543109509e17de25110203ef.tar.bz2 luafilesystem-83faa7e05d288dcb543109509e17de25110203ef.zip | |
Simplify and clarify metatable creation functions.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lfs.c | 22 |
1 files changed, 12 insertions, 10 deletions
| @@ -534,19 +534,18 @@ static int dir_iter_factory (lua_State *L) { | |||
| 534 | */ | 534 | */ |
| 535 | static int dir_create_meta (lua_State *L) { | 535 | static int dir_create_meta (lua_State *L) { |
| 536 | luaL_newmetatable (L, DIR_METATABLE); | 536 | luaL_newmetatable (L, DIR_METATABLE); |
| 537 | /* set its __gc field */ | 537 | |
| 538 | lua_pushstring (L, "__index"); | 538 | /* Method table */ |
| 539 | lua_newtable(L); | 539 | lua_newtable(L); |
| 540 | lua_pushstring (L, "next"); | ||
| 541 | lua_pushcfunction (L, dir_iter); | 540 | lua_pushcfunction (L, dir_iter); |
| 542 | lua_settable(L, -3); | 541 | lua_setfield(L, -2, "next"); |
| 543 | lua_pushstring (L, "close"); | ||
| 544 | lua_pushcfunction (L, dir_close); | 542 | lua_pushcfunction (L, dir_close); |
| 545 | lua_settable(L, -3); | 543 | lua_setfield(L, -2, "close"); |
| 546 | lua_settable (L, -3); | 544 | |
| 547 | lua_pushstring (L, "__gc"); | 545 | /* Metamethods */ |
| 546 | lua_setfield(L, -2, "__index"); | ||
| 548 | lua_pushcfunction (L, dir_close); | 547 | lua_pushcfunction (L, dir_close); |
| 549 | lua_settable (L, -3); | 548 | lua_setfield (L, -2, "__gc"); |
| 550 | return 1; | 549 | return 1; |
| 551 | } | 550 | } |
| 552 | 551 | ||
| @@ -555,10 +554,13 @@ static int dir_create_meta (lua_State *L) { | |||
| 555 | */ | 554 | */ |
| 556 | static int lock_create_meta (lua_State *L) { | 555 | static int lock_create_meta (lua_State *L) { |
| 557 | luaL_newmetatable (L, LOCK_METATABLE); | 556 | luaL_newmetatable (L, LOCK_METATABLE); |
| 558 | /* set its __gc field */ | 557 | |
| 558 | /* Method table */ | ||
| 559 | lua_newtable(L); | 559 | lua_newtable(L); |
| 560 | lua_pushcfunction(L, lfs_unlock_dir); | 560 | lua_pushcfunction(L, lfs_unlock_dir); |
| 561 | lua_setfield(L, -2, "free"); | 561 | lua_setfield(L, -2, "free"); |
| 562 | |||
| 563 | /* Metamethods */ | ||
| 562 | lua_setfield(L, -2, "__index"); | 564 | lua_setfield(L, -2, "__index"); |
| 563 | lua_pushcfunction(L, lfs_unlock_dir); | 565 | lua_pushcfunction(L, lfs_unlock_dir); |
| 564 | lua_setfield(L, -2, "__gc"); | 566 | lua_setfield(L, -2, "__gc"); |
