|
@@ -39,45 +39,10 @@ namespace love
|
|
namespace math
|
|
namespace math
|
|
{
|
|
{
|
|
|
|
|
|
-int w__random(lua_State *L)
|
|
|
|
|
|
+int w__getRandomGenerator(lua_State *L)
|
|
{
|
|
{
|
|
- lua_pushnumber(L, Math::instance.random());
|
|
|
|
- return 1;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int w_randomNormal(lua_State *L)
|
|
|
|
-{
|
|
|
|
- double stddev = luaL_optnumber(L, 1, 1.0);
|
|
|
|
- double mean = luaL_optnumber(L, 2, 0.0);
|
|
|
|
- double r = Math::instance.randomNormal(stddev);
|
|
|
|
-
|
|
|
|
- lua_pushnumber(L, r + mean);
|
|
|
|
- return 1;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int w_setRandomSeed(lua_State *L)
|
|
|
|
-{
|
|
|
|
- luax_catchexcept(L, [&](){ Math::instance.setRandomSeed(luax_checkrandomseed(L, 1)); });
|
|
|
|
- return 0;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int w_getRandomSeed(lua_State *L)
|
|
|
|
-{
|
|
|
|
- RandomGenerator::Seed s = Math::instance.getRandomSeed();
|
|
|
|
- lua_pushnumber(L, (lua_Number) s.b32.low);
|
|
|
|
- lua_pushnumber(L, (lua_Number) s.b32.high);
|
|
|
|
- return 2;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int w_setRandomState(lua_State *L)
|
|
|
|
-{
|
|
|
|
- luax_catchexcept(L, [&](){ Math::instance.setRandomState(luax_checkstring(L, 1)); });
|
|
|
|
- return 0;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int w_getRandomState(lua_State *L)
|
|
|
|
-{
|
|
|
|
- luax_pushstring(L, Math::instance.getRandomState());
|
|
|
|
|
|
+ RandomGenerator *t = Math::instance.getRandomGenerator();
|
|
|
|
+ luax_pushtype(L, MATH_RANDOM_GENERATOR_ID, t);
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -423,8 +388,6 @@ int w_decompress(lua_State *L)
|
|
// C functions in a struct, necessary for the FFI versions of math functions.
|
|
// C functions in a struct, necessary for the FFI versions of math functions.
|
|
struct FFI_Math
|
|
struct FFI_Math
|
|
{
|
|
{
|
|
- double (*random)(void);
|
|
|
|
-
|
|
|
|
float (*noise1)(float x);
|
|
float (*noise1)(float x);
|
|
float (*noise2)(float x, float y);
|
|
float (*noise2)(float x, float y);
|
|
float (*noise3)(float x, float y, float z);
|
|
float (*noise3)(float x, float y, float z);
|
|
@@ -436,11 +399,6 @@ struct FFI_Math
|
|
|
|
|
|
static FFI_Math ffifuncs =
|
|
static FFI_Math ffifuncs =
|
|
{
|
|
{
|
|
- [](void) -> double // random
|
|
|
|
- {
|
|
|
|
- return Math::instance.random();
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
[](float x) -> float // noise1
|
|
[](float x) -> float // noise1
|
|
{
|
|
{
|
|
return Math::instance.noise(x);
|
|
return Math::instance.noise(x);
|
|
@@ -471,12 +429,9 @@ static FFI_Math ffifuncs =
|
|
// List of functions to wrap.
|
|
// List of functions to wrap.
|
|
static const luaL_Reg functions[] =
|
|
static const luaL_Reg functions[] =
|
|
{
|
|
{
|
|
- { "_random", w__random }, // love.math.random is inside wrap_Math.lua.
|
|
|
|
- { "randomNormal", w_randomNormal },
|
|
|
|
- { "setRandomSeed", w_setRandomSeed },
|
|
|
|
- { "getRandomSeed", w_getRandomSeed },
|
|
|
|
- { "setRandomState", w_setRandomState },
|
|
|
|
- { "getRandomState", w_getRandomState },
|
|
|
|
|
|
+ // love.math.random etc. are defined in wrap_Math.lua.
|
|
|
|
+
|
|
|
|
+ { "_getRandomGenerator", w__getRandomGenerator },
|
|
{ "newRandomGenerator", w_newRandomGenerator },
|
|
{ "newRandomGenerator", w_newRandomGenerator },
|
|
{ "newBezierCurve", w_newBezierCurve },
|
|
{ "newBezierCurve", w_newBezierCurve },
|
|
{ "triangulate", w_triangulate },
|
|
{ "triangulate", w_triangulate },
|
|
@@ -510,7 +465,7 @@ extern "C" int luaopen_love_math(lua_State *L)
|
|
|
|
|
|
int n = luax_register_module(L, w);
|
|
int n = luax_register_module(L, w);
|
|
|
|
|
|
- // Execute wrap_Event.lua, sending the math table and ffifuncs pointer as args.
|
|
|
|
|
|
+ // Execute wrap_Math.lua, sending the math table and ffifuncs pointer as args.
|
|
luaL_loadbuffer(L, math_lua, sizeof(math_lua), "wrap_Math.lua");
|
|
luaL_loadbuffer(L, math_lua, sizeof(math_lua), "wrap_Math.lua");
|
|
lua_pushvalue(L, -2);
|
|
lua_pushvalue(L, -2);
|
|
lua_pushlightuserdata(L, &ffifuncs);
|
|
lua_pushlightuserdata(L, &ffifuncs);
|