[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Missing pow function?
- From: Edgar Toernig <froese@...>
- Date: Fri, 13 Apr 2001 02:38:15 +0200
Hi,
Marius Kjeldahl wrote:
>
> I'm trying to use the pow function, but it does not work.
I assume you are trying something like pow(a,b)? Try a^b instead.
Power is an operator, not a function.
> While most of the mathematical functions are defined in the luaL_reg
> mathlib structure in lmathlib.c, it seems pow is defined differently in
> lua_mathlibopen:
>
> lua_pushcfunction(L, math_pow);
> lua_settagmethod(L, LUA_TNUMBER, "pow");
>
> I'm new to lua, but I would guess this code is supposed to demo how to
> define pow as a function in a different manner than using the luaL_reg
> mathlib structure.
It's not a demo ;-) It registers a handler that is called when the ^ (pow)
operator is applied to a number.
(The pow-function requires C's math library and is therefore not in the
standard Lua executor but together with all other math functions in Lua's
math library.)
> Is pow supposed to be supported, and if so can I safely assume that it
> is a bug for now (and add it the same way the other functions are being
> used)?
Not a bug, just a misunderstanding. You could of course put it also in
the luaL_reg mathlib structure and get it as a function. But the ^ oper-
ator may be more comfortable.
Ciao, ET.