lua-users home
lua-l archive

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


_G["print"]("hello to you too")

On Dec 12, 2006, at 12:46 AM, Austin Xu Wang wrote:

$ lua
Lua 5.1.1  Copyright (C) 1994-2006 Lua.org, PUC-Rio
array={print}
array[1]("Hello World!")
Hello World!


On 12/12/06, BrillyWu <brillywu@gmail.com> wrote:
In lua baselib.c,it give us a lot of base function,such as:

static const struct luaL_reg iolib[] = {
 {LUA_ERRORMESSAGE, errorfb},
 {"clock", io_clock},
 {"date", io_date},
 {"debug", io_debug},
 {"execute", io_execute},
 {"exit", io_exit},
 {"getenv", io_getenv},
 {"remove", io_remove},
 {"rename", io_rename},
 {"setlocale", setloc},
 {"tmpname", io_tmpname}
};

static const struct luaL_reg iolibtag[] = {
 {"appendto", io_appendto},
 {"closefile", io_close},
 {"flush", io_flush},
 {"openfile", io_open},
 {"read", io_read},
 {"readfrom", io_readfrom},
 {"seek", io_seek},
 {"write", io_write},
 {"writeto", io_writeto}
};

and in my project,I definded a lot of function of myself.and register to
lua.

in Lua script,I can use this function:

test.lua


function main()
   print("hello wolrd");
end function

main();

-----------------------------
I use the function by its funciton name:"print",How can I call print
function,not by its function name,but use the index of the function in the
array?