lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 6fef372fb8b14be806070d6c2e96fd2b9cb2e41a
parent 052a1cc46c3b1a2e589bd061be0e1bd153c9e47a
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Fri, 21 Mar 1997 15:37:08 -0300

mathlib now uses i.m. for "pow" operator.

Diffstat:
Mfallback.c | 4++--
Mmathlib.c | 26+++++---------------------
2 files changed, 7 insertions(+), 23 deletions(-)

diff --git a/fallback.c b/fallback.c @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_fallback="$Id: fallback.c,v 1.30 1997/03/20 19:20:43 roberto Exp roberto $"; +char *rcs_fallback="$Id: fallback.c,v 1.31 1997/03/20 20:36:19 roberto Exp roberto $"; #include <stdio.h> #include <string.h> @@ -351,7 +351,7 @@ void luaI_setfallback (void) } else if (strcmp(name, "arith") == 0) { /* old arith fallback */ int i; - oldfunc = luaI_IMtable[LUA_T_USERDATA].int_method[IM_ADD]; + oldfunc = luaI_IMtable[LUA_T_USERDATA].int_method[IM_POW]; for (i=IM_ADD; i<=IM_UNM; i++) /* ORDER IM */ fillvalids(i, luaI_Address(func)); replace = typeFB; diff --git 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 <stdlib.h> #include <math.h> @@ -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); }