diff options
Diffstat (limited to 'lstrlib.c')
-rw-r--r-- | lstrlib.c | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.110 2005/03/08 20:10:05 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.111 2005/03/22 16:54:29 roberto Exp roberto $ |
3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -772,11 +772,26 @@ static const luaL_reg strlib[] = { | |||
772 | }; | 772 | }; |
773 | 773 | ||
774 | 774 | ||
775 | static void createmetatable (lua_State *L) { | ||
776 | lua_newtable(L); /* create metatable for strings */ | ||
777 | lua_pushliteral(L, ""); /* dummy string */ | ||
778 | lua_pushvalue(L, -2); | ||
779 | lua_setmetatable(L, -2); /* set string metatable */ | ||
780 | lua_pop(L, 1); /* pop dummy string */ | ||
781 | lua_pushvalue(L, -2); /* string library... */ | ||
782 | lua_setfield(L, -2, "__index"); /* ...is the __index metamethod */ | ||
783 | lua_getfield(L, -2, "len"); | ||
784 | lua_setfield(L, -2, "__siz"); | ||
785 | lua_pop(L, 1); /* pop metatable */ | ||
786 | } | ||
787 | |||
788 | |||
775 | /* | 789 | /* |
776 | ** Open string library | 790 | ** Open string library |
777 | */ | 791 | */ |
778 | LUALIB_API int luaopen_string (lua_State *L) { | 792 | LUALIB_API int luaopen_string (lua_State *L) { |
779 | luaL_openlib(L, LUA_STRLIBNAME, strlib, 0); | 793 | luaL_openlib(L, LUA_STRLIBNAME, strlib, 0); |
794 | createmetatable(L); | ||
780 | return 1; | 795 | return 1; |
781 | } | 796 | } |
782 | 797 | ||