new module policy: C modules do not create globals and do not register

themselves with 'require' (let 'require' do its work); new auxiliary
functions luaL_newlib/luaL_newlibtable/luaL_setfuncs/luaL_requiref.
Old luaL_register will be deprecated.
This commit is contained in:
Roberto Ierusalimschy
2010-07-02 08:38:13 -03:00
parent a139e2e003
commit 7192afafee
14 changed files with 104 additions and 55 deletions

View File

@@ -1,5 +1,5 @@
/*
** $Id: lmathlib.c,v 1.73 2009/03/17 17:55:39 roberto Exp roberto $
** $Id: lmathlib.c,v 1.74 2009/11/24 12:05:44 roberto Exp roberto $
** Standard mathematical library
** See Copyright Notice in lua.h
*/
@@ -263,7 +263,7 @@ static const luaL_Reg mathlib[] = {
** Open math library
*/
LUAMOD_API int luaopen_math (lua_State *L) {
luaL_register(L, LUA_MATHLIBNAME, mathlib);
luaL_newlib(L, mathlib);
lua_pushnumber(L, PI);
lua_setfield(L, -2, "pi");
lua_pushnumber(L, HUGE_VAL);