CHDK_DE Vorschauversion  Trunk Rev. 6014
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
lmathlib.c-Dateireferenz
#include <stdlib.h>
#include <math.h>
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
+ Include-Abhängigkeitsdiagramm für lmathlib.c:

gehe zum Quellcode dieser Datei

Makrodefinitionen

#define lmathlib_c
 
#define LUA_LIB
 
#define PI   (3.14159265358979323846)
 
#define RADIANS_PER_DEGREE   (PI/180.0)
 

Funktionen

static int math_abs (lua_State *L)
 
static int math_pow (lua_State *L)
 
static int math_min (lua_State *L)
 
static int math_max (lua_State *L)
 
static int math_random (lua_State *L)
 
static int math_randomseed (lua_State *L)
 
LUALIB_API int luaopen_math (lua_State *L)
 

Variablen

static const luaL_Reg mathlib []
 

Makro-Dokumentation

#define lmathlib_c

Definiert in Zeile 11 der Datei lmathlib.c.

#define LUA_LIB

Definiert in Zeile 12 der Datei lmathlib.c.

#define PI   (3.14159265358979323846)

Definiert in Zeile 21 der Datei lmathlib.c.

#define RADIANS_PER_DEGREE   (PI/180.0)

Definiert in Zeile 22 der Datei lmathlib.c.

Dokumentation der Funktionen

LUALIB_API int luaopen_math ( lua_State L)

Definiert in Zeile 272 der Datei lmathlib.c.

272  {
274 #if 0
275  lua_pushnumber(L, PI);
276  lua_setfield(L, -2, "pi");
277  lua_pushnumber(L, HUGE_VAL);
278  lua_setfield(L, -2, "huge");
279 #endif
280 #if defined(LUA_COMPAT_MOD)
281  lua_getfield(L, -1, "fmod");
282  lua_setfield(L, -2, "mod");
283 #endif
284  return 1;
285 }
static int math_abs ( lua_State L)
static

Definiert in Zeile 26 der Datei lmathlib.c.

26  {
27 #if 0
29 #else
31 #endif
32  return 1;
33 }
static int math_max ( lua_State L)
static

Definiert in Zeile 176 der Datei lmathlib.c.

176  {
177  int n = lua_gettop(L); /* number of arguments */
178  lua_Number dmax = luaL_checknumber(L, 1);
179  int i;
180  for (i=2; i<=n; i++) {
181  lua_Number d = luaL_checknumber(L, i);
182  if (d > dmax)
183  dmax = d;
184  }
185  lua_pushnumber(L, dmax);
186  return 1;
187 }
static int math_min ( lua_State L)
static

Definiert in Zeile 162 der Datei lmathlib.c.

162  {
163  int n = lua_gettop(L); /* number of arguments */
164  lua_Number dmin = luaL_checknumber(L, 1);
165  int i;
166  for (i=2; i<=n; i++) {
167  lua_Number d = luaL_checknumber(L, i);
168  if (d < dmin)
169  dmin = d;
170  }
171  lua_pushnumber(L, dmin);
172  return 1;
173 }
static int math_pow ( lua_State L)
static

Definiert in Zeile 114 der Datei lmathlib.c.

114  {
115 #if 0
117 #else
119 #endif
120  return 1;
121 }
static int math_random ( lua_State L)
static

Definiert in Zeile 190 der Datei lmathlib.c.

190  {
191  /* the `%' avoids the (rare) case of r==1, and is needed also because on
192  some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */
193 #if 0
194  lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX;
195 #endif
196  switch (lua_gettop(L)) { /* check number of arguments */
197 #if 0
198  case 0: { /* no arguments */
199  lua_pushnumber(L, r); /* Number between 0 and 1 */
200  break;
201  }
202 #endif
203  case 1: { /* only upper limit */
204  int u = luaL_checkint(L, 1);
205  luaL_argcheck(L, 1<=u, 1, "interval is empty");
206 #if 0
207  lua_pushnumber(L, floor(r*u)+1); /* int between 1 and `u' */
208 #else
209  lua_pushnumber(L, rand()%u+1);
210 #endif
211  break;
212  }
213  case 2: { /* lower and upper limits */
214  int l = luaL_checkint(L, 1);
215  int u = luaL_checkint(L, 2);
216  luaL_argcheck(L, l<=u, 2, "interval is empty");
217 #if 0
218  lua_pushnumber(L, floor(r*(u-l+1))+l); /* int between `l' and `u' */
219 #else
220  lua_pushnumber(L, rand()%(u-l+1)+l);
221 #endif
222  break;
223  }
224  default: return luaL_error(L, "wrong number of arguments");
225  }
226  return 1;
227 }
static int math_randomseed ( lua_State L)
static

Definiert in Zeile 230 der Datei lmathlib.c.

230  {
231  srand(luaL_checkint(L, 1));
232  return 0;
233 }

Variablen-Dokumentation

const luaL_Reg mathlib[]
static

Definiert in Zeile 236 der Datei lmathlib.c.