From 3ec9ee0d0f81fd0aabaef1303f971b2f7ee12315 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 30 Apr 1996 18:13:55 -0300 Subject: new function "luaI_openlib" to help open libs. --- mathlib.c | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'mathlib.c') diff --git a/mathlib.c b/mathlib.c index 5e02908e..f01e149d 100644 --- a/mathlib.c +++ b/mathlib.c @@ -3,7 +3,7 @@ ** Mathematics library to LUA */ -char *rcs_mathlib="$Id: mathlib.c,v 1.15 1996/04/22 18:00:37 roberto Exp roberto $"; +char *rcs_mathlib="$Id: mathlib.c,v 1.16 1996/04/25 14:10:00 roberto Exp roberto $"; #include #include @@ -195,33 +195,36 @@ static void math_randomseed (void) } +static struct lua_reg mathlib[] = { +{"abs", math_abs}, +{"sin", math_sin}, +{"cos", math_cos}, +{"tan", math_tan}, +{"asin", math_asin}, +{"acos", math_acos}, +{"atan", math_atan}, +{"atan2", math_atan2}, +{"ceil", math_ceil}, +{"floor", math_floor}, +{"mod", math_mod}, +{"sqrt", math_sqrt}, +{"min", math_min}, +{"max", math_max}, +{"log", math_log}, +{"log10", math_log10}, +{"exp", math_exp}, +{"deg", math_deg}, +{"rad", math_rad}, +{"random", math_random}, +{"randomseed", math_randomseed} +}; /* ** Open math library */ void mathlib_open (void) { - lua_register ("abs", math_abs); - lua_register ("sin", math_sin); - lua_register ("cos", math_cos); - lua_register ("tan", math_tan); - lua_register ("asin", math_asin); - lua_register ("acos", math_acos); - lua_register ("atan", math_atan); - lua_register ("atan2", math_atan2); - lua_register ("ceil", math_ceil); - lua_register ("floor", math_floor); - lua_register ("mod", math_mod); - lua_register ("sqrt", math_sqrt); - lua_register ("min", math_min); - lua_register ("max", math_max); - lua_register ("log", math_log); - lua_register ("log10", math_log10); - lua_register ("exp", math_exp); - lua_register ("deg", math_deg); - lua_register ("rad", math_rad); - lua_register ("random", math_random); - lua_register ("randomseed", math_randomseed); - - old_pow = lua_refobject(lua_setfallback("arith", math_pow), 1); + luaI_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0]))); + old_pow = lua_refobject(lua_setfallback("arith", math_pow), 1); } + -- cgit v1.2.3-55-g6feb