diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-06-24 14:23:16 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-06-24 14:23:16 -0300 |
commit | 1a4c428d6d2c9c9a35ceb7d4fb054f83c89f98e5 (patch) | |
tree | 8cee732c0860e616b43c4d92e52741642ea88d7d | |
parent | 2394604d10cd9c960b4c1d73ee32672830954139 (diff) | |
download | lua-1a4c428d6d2c9c9a35ceb7d4fb054f83c89f98e5.tar.gz lua-1a4c428d6d2c9c9a35ceb7d4fb054f83c89f98e5.tar.bz2 lua-1a4c428d6d2c9c9a35ceb7d4fb054f83c89f98e5.zip |
new function `newproxy'
-rw-r--r-- | lbaselib.c | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.82 2002/06/18 15:19:27 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.83 2002/06/20 20:41:46 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -293,6 +293,25 @@ static int luaB_tostring (lua_State *L) { | |||
293 | } | 293 | } |
294 | 294 | ||
295 | 295 | ||
296 | static int luaB_newproxy (lua_State *L) { | ||
297 | void *u; | ||
298 | lua_pushnil(L); /* default argument (if there is nothing at stack[1]) */ | ||
299 | u = lua_newuserdata(L, sizeof(lua_CFunction)); /* create proxy */ | ||
300 | *(lua_CFunction *)u = luaB_newproxy; /* mark it as a proxy */ | ||
301 | if (lua_toboolean(L, 1) == 0) | ||
302 | return 1; /* no metatable */ | ||
303 | else if ((u = lua_touserdata(L, 1)) != NULL) { | ||
304 | luaL_arg_check(L, *(lua_CFunction *)u == luaB_newproxy, 1, "invalid proxy"); | ||
305 | lua_getmetatable(L, 1); /* reuse metatable */ | ||
306 | } | ||
307 | else { | ||
308 | luaL_check_type(L, 1, LUA_TBOOLEAN); | ||
309 | lua_newtable(L); /* create a new metatable */ | ||
310 | } | ||
311 | lua_setmetatable(L, -2); | ||
312 | return 1; | ||
313 | } | ||
314 | |||
296 | 315 | ||
297 | /* | 316 | /* |
298 | ** {====================================================== | 317 | ** {====================================================== |
@@ -406,6 +425,7 @@ static const luaL_reg base_funcs[] = { | |||
406 | {"tostring", luaB_tostring}, | 425 | {"tostring", luaB_tostring}, |
407 | {"type", luaB_type}, | 426 | {"type", luaB_type}, |
408 | {"assert", luaB_assert}, | 427 | {"assert", luaB_assert}, |
428 | {"newproxy", luaB_newproxy}, | ||
409 | {"unpack", luaB_unpack}, | 429 | {"unpack", luaB_unpack}, |
410 | {"rawequal", luaB_rawequal}, | 430 | {"rawequal", luaB_rawequal}, |
411 | {"rawget", luaB_rawget}, | 431 | {"rawget", luaB_rawget}, |