From 6fef372fb8b14be806070d6c2e96fd2b9cb2e41a Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 21 Mar 1997 15:37:28 -0300 Subject: mathlib now uses i.m. for "pow" operator. --- mathlib.c | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) (limited to 'mathlib.c') diff --git a/mathlib.c b/mathlib.c index 798ba322..16d2a815 100644 --- a/mathlib.c +++ b/mathlib.c @@ -3,7 +3,7 @@ ** Mathematics library to LUA */ -char *rcs_mathlib="$Id: mathlib.c,v 1.19 1997/03/17 17:01:10 roberto Exp roberto $"; +char *rcs_mathlib="$Id: mathlib.c,v 1.20 1997/03/18 15:30:50 roberto Exp roberto $"; #include #include @@ -105,28 +105,12 @@ static void math_sqrt (void) lua_pushnumber (sqrt(d)); } -static int old_pow; static void math_pow (void) { - lua_Object o1 = lua_getparam (1); - lua_Object o2 = lua_getparam (2); - lua_Object op = lua_getparam(3); - if (!lua_isnumber(o1) || !lua_isnumber(o2) || *(lua_getstring(op)) != 'p') - { - lua_Object old = lua_getref(old_pow); - lua_pushobject(o1); - lua_pushobject(o2); - lua_pushobject(op); - if (lua_callfunction(old) != 0) - lua_error(NULL); - } - else - { - double d1 = lua_getnumber(o1); - double d2 = lua_getnumber(o2); - lua_pushnumber (pow(d1,d2)); - } + double d1 = luaL_check_number(1, "exp"); + double d2 = luaL_check_number(2, "exp"); + lua_pushnumber(pow(d1,d2)); } static void math_min (void) @@ -226,6 +210,6 @@ static struct luaL_reg mathlib[] = { void mathlib_open (void) { luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0]))); - old_pow = lua_refobject(lua_setfallback("arith", math_pow), 1); + lua_setintmethod(0, "pow", math_pow); } -- cgit v1.2.3-55-g6feb