mirror of https://github.com/rusefi/lua.git
mathlib now uses i.m. for "pow" operator.
This commit is contained in:
parent
052a1cc46c
commit
6fef372fb8
|
@ -3,7 +3,7 @@
|
||||||
** TecCGraf - PUC-Rio
|
** 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 <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -351,7 +351,7 @@ void luaI_setfallback (void)
|
||||||
}
|
}
|
||||||
else if (strcmp(name, "arith") == 0) { /* old arith fallback */
|
else if (strcmp(name, "arith") == 0) { /* old arith fallback */
|
||||||
int i;
|
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 */
|
for (i=IM_ADD; i<=IM_UNM; i++) /* ORDER IM */
|
||||||
fillvalids(i, luaI_Address(func));
|
fillvalids(i, luaI_Address(func));
|
||||||
replace = typeFB;
|
replace = typeFB;
|
||||||
|
|
24
mathlib.c
24
mathlib.c
|
@ -3,7 +3,7 @@
|
||||||
** Mathematics library to LUA
|
** 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 <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
@ -105,29 +105,13 @@ static void math_sqrt (void)
|
||||||
lua_pushnumber (sqrt(d));
|
lua_pushnumber (sqrt(d));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int old_pow;
|
|
||||||
|
|
||||||
static void math_pow (void)
|
static void math_pow (void)
|
||||||
{
|
{
|
||||||
lua_Object o1 = lua_getparam (1);
|
double d1 = luaL_check_number(1, "exp");
|
||||||
lua_Object o2 = lua_getparam (2);
|
double d2 = luaL_check_number(2, "exp");
|
||||||
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));
|
lua_pushnumber(pow(d1,d2));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void math_min (void)
|
static void math_min (void)
|
||||||
{
|
{
|
||||||
|
@ -226,6 +210,6 @@ static struct luaL_reg mathlib[] = {
|
||||||
void mathlib_open (void)
|
void mathlib_open (void)
|
||||||
{
|
{
|
||||||
luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0])));
|
luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0])));
|
||||||
old_pow = lua_refobject(lua_setfallback("arith", math_pow), 1);
|
lua_setintmethod(0, "pow", math_pow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue