[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: dofile and ...
- From: "Peter Shook" <pshook@...>
- Date: Sat, 04 Sep 2004 11:20:05 -0400
Good work guys, replacing arg with ... is a great idea.
It makes code easier to read:
function printf(...) io.write(string.format(...)) end
And being able to access the args passed to the function returned by
loadstring/loadfile is really great too.
Here is a modified version of dofile for those who can't wait to play with
this feature:
static int luaB_dofile (lua_State *L) {
const char *fname = luaL_optstring(L, 1, NULL);
int n = lua_gettop(L);
if (luaL_loadfile(L, fname) != 0) lua_error(L);
lua_insert(L, 1);
lua_call(L, n, LUA_MULTRET);
return lua_gettop(L);
}
$ cat x.lua
print(...)
$ bin/lua
Lua 5.1 (work1) Copyright (C) 1994-2004 Tecgraf, PUC-Rio
dofile('x.lua',1,2,3)
x.lua 1 2 3
Cheers,
- Peter
_________________________________________________________________
MSN® Calendar keeps you organized and takes the effort out of scheduling
get-togethers.
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
Start enjoying all the benefits of MSN® Premium right now and get the
first two months FREE*.