summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
author Luca Bruno <lucab@debian.org>2015-04-18 10:48:31 +0200
committer Luca Bruno <lucab@debian.org>2015-04-21 21:49:42 +0200
commitd1436e698aeb269e6f024bae5d78307d5258b00b (patch)
tree252f8a0418a483725c80cdb8b72f0157e8d5d25a /src
parent0d7860c6753dcaf6cc98c8395f4b4a915500c4d5 (diff)
luaengine: accept any LUA number type as coordinate
This commit fixes a type confusion bug in all draw_*() API methods. When decimal (ie. subpixels) values were passed by user scripts, they were incorrectly casted from float to plain integers, resulting in incorrect graphical artifacts. As this may happen quite often within scripts manipulating numerical values in LUA, we now also accept decimal values as coordinates. Signed-off-by: Luca Bruno <lucab@debian.org>
Diffstat (limited to 'src')
-rw-r--r--src/emu/luaengine.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/emu/luaengine.c b/src/emu/luaengine.c
index 12be9947cae..98a0f1a86c9 100644
--- a/src/emu/luaengine.c
+++ b/src/emu/luaengine.c
@@ -642,10 +642,10 @@ int lua_engine::lua_screen::l_draw_box(lua_State *L)
int sc_width = sc->visible_area().width();
int sc_height = sc->visible_area().height();
float x1, y1, x2, y2;
- x1 = MIN(MAX(0, lua_tointeger(L, 2)), sc_width-1) / static_cast<float>(sc_width);
- y1 = MIN(MAX(0, lua_tointeger(L, 3)), sc_height-1) / static_cast<float>(sc_height);
- x2 = MIN(MAX(0, lua_tointeger(L, 4)), sc_width-1) / static_cast<float>(sc_width);
- y2 = MIN(MAX(0, lua_tointeger(L, 5)), sc_height-1) / static_cast<float>(sc_height);
+ x1 = MIN(MAX(0, lua_tonumber(L, 2)), sc_width-1) / static_cast<float>(sc_width);
+ y1 = MIN(MAX(0, lua_tonumber(L, 3)), sc_height-1) / static_cast<float>(sc_height);
+ x2 = MIN(MAX(0, lua_tonumber(L, 4)), sc_width-1) / static_cast<float>(sc_width);
+ y2 = MIN(MAX(0, lua_tonumber(L, 5)), sc_height-1) / static_cast<float>(sc_height);
UINT32 bgcolor = lua_tounsigned(L, 6);
UINT32 fgcolor = lua_tounsigned(L, 7);
@@ -680,10 +680,10 @@ int lua_engine::lua_screen::l_draw_line(lua_State *L)
int sc_width = sc->visible_area().width();
int sc_height = sc->visible_area().height();
float x1, y1, x2, y2;
- x1 = MIN(MAX(0, lua_tointeger(L, 2)), sc_width-1) / static_cast<float>(sc_width);
- y1 = MIN(MAX(0, lua_tointeger(L, 3)), sc_height-1) / static_cast<float>(sc_height);
- x2 = MIN(MAX(0, lua_tointeger(L, 4)), sc_width-1) / static_cast<float>(sc_width);
- y2 = MIN(MAX(0, lua_tointeger(L, 5)), sc_height-1) / static_cast<float>(sc_height);
+ x1 = MIN(MAX(0, lua_tonumber(L, 2)), sc_width-1) / static_cast<float>(sc_width);
+ y1 = MIN(MAX(0, lua_tonumber(L, 3)), sc_height-1) / static_cast<float>(sc_height);
+ x2 = MIN(MAX(0, lua_tonumber(L, 4)), sc_width-1) / static_cast<float>(sc_width);
+ y2 = MIN(MAX(0, lua_tonumber(L, 5)), sc_height-1) / static_cast<float>(sc_height);
UINT32 color = lua_tounsigned(L, 6);
// draw the line
@@ -711,8 +711,8 @@ int lua_engine::lua_screen::l_draw_text(lua_State *L)
// retrieve all parameters
int sc_width = sc->visible_area().width();
int sc_height = sc->visible_area().height();
- float x = MIN(MAX(0, lua_tointeger(L, 2)), sc_width-1) / static_cast<float>(sc_width);
- float y = MIN(MAX(0, lua_tointeger(L, 3)), sc_height-1) / static_cast<float>(sc_height);
+ float x = MIN(MAX(0, lua_tonumber(L, 2)), sc_width-1) / static_cast<float>(sc_width);
+ float y = MIN(MAX(0, lua_tonumber(L, 3)), sc_height-1) / static_cast<float>(sc_height);
const char *msg = luaL_checkstring(L,4);
// TODO: add optional parameters (colors, etc.)