From 077b5450be53fd42613917a44c4b4d0c4367236e Mon Sep 17 00:00:00 2001 From: selimanac Date: Sun, 21 Mar 2021 22:30:04 +0300 Subject: [PATCH] Fix for #4 --- README.md | 4 ++++ game.project | 2 +- pcgrandom/src/pcgrandom.cpp | 15 ++++++++------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7095017..641f05f 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,10 @@ Testing entropy. ## Release Notes +1.2.5 + +- Fix for [#4](https://github.com/selimanac/defold-random/issues/4#issue-837151758) + 1.2.4 - `rnd.double_range(min, max)` added. diff --git a/game.project b/game.project index 0e7a505..b03d38a 100644 --- a/game.project +++ b/game.project @@ -1,6 +1,6 @@ [project] title = defold-random -version = 1.2.1 +version = 1.2.5 [bootstrap] main_collection = /example/main.collectionc diff --git a/pcgrandom/src/pcgrandom.cpp b/pcgrandom/src/pcgrandom.cpp index e8c0f18..4ef5eab 100644 --- a/pcgrandom/src/pcgrandom.cpp +++ b/pcgrandom/src/pcgrandom.cpp @@ -63,6 +63,7 @@ static int double_range(lua_State *L) assert(top + 1 == lua_gettop(L)); return 1; } + static int double_num(lua_State *L) { int top = lua_gettop(L); @@ -77,7 +78,7 @@ static int roll(lua_State *L) { int top = lua_gettop(L); num = (int)pcg32_boundedrand_r(&rng, 6) + 1; - lua_pushinteger(L, num); + lua_pushnumber(L, num); assert(top + 1 == lua_gettop(L)); return 1; } @@ -86,7 +87,7 @@ static int toss(lua_State *L) { int top = lua_gettop(L); num = pcg32_boundedrand_r(&rng, 2) ? 0 : 1; - lua_pushinteger(L, num); + lua_pushnumber(L, num); assert(top + 1 == lua_gettop(L)); return 1; } @@ -94,12 +95,12 @@ static int toss(lua_State *L) static int range(lua_State *L) { int top = lua_gettop(L); - min = luaL_checkinteger(L, 1); - max = luaL_checkinteger(L, 2); + min = luaL_checknumber(L, 1); + max = luaL_checknumber(L, 2); if (min == max) { - lua_pushinteger(L, min); + lua_pushnumber(L, min); return 1; } @@ -111,7 +112,7 @@ static int range(lua_State *L) max++; num = pcg32_boundedrand_r(&rng, (max - min)) + min; - lua_pushinteger(L, num); + lua_pushnumber(L, num); assert(top + 1 == lua_gettop(L)); return 1; } @@ -139,7 +140,7 @@ static int number(lua_State *L) { int top = lua_gettop(L); num = pcg32_random_r(&rng); - lua_pushinteger(L, num); + lua_pushnumber(L, num); assert(top + 1 == lua_gettop(L)); return 1; }