lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

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


$ bin/lua
Lua 5.1 (work1)  Copyright (C) 1994-2004 Tecgraf, PUC-Rio

x.lua   1       2       3


- Peter

MSN® Calendar keeps you organized and takes the effort out of scheduling get-togethers. Start enjoying all the benefits of MSN® Premium right now and get the first two months FREE*.