summaryrefslogtreecommitdiff
path: root/lstrlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lstrlib.c')
-rw-r--r--lstrlib.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/lstrlib.c b/lstrlib.c
index 1a2e6c29..93f8e776 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -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
775static 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*/
778LUALIB_API int luaopen_string (lua_State *L) { 792LUALIB_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