fix for sudden exit if passing bad arguments into a lua gui at a time when it must be deferred

This commit is contained in:
nitsuja 2009-11-19 08:01:55 +00:00
parent 5bc0040f1a
commit 7416f2a973
1 changed files with 25 additions and 22 deletions

View File

@ -2928,12 +2928,13 @@ static void LuaDisplayString (const char *str, int x, int y, u32 color, u32 outl
DEFINE_LUA_FUNCTION(gui_text, "x,y,str[,color=\"white\"[,outline=\"black\"]]")
{
int x = luaL_checkinteger(L,1); // have to check for errors before deferring
int y = luaL_checkinteger(L,2);
if(DeferGUIFuncIfNeeded(L))
return 0; // we have to wait until later to call this function because we haven't emulated the next frame yet
// (the only way to avoid this deferring is to be in a gui.register or emu.registerafter callback)
int x = luaL_checkinteger(L,1);
int y = luaL_checkinteger(L,2);
const char* str = toCString(L,3); // better than using luaL_checkstring here (more permissive)
if(str && *str)
@ -2952,13 +2953,14 @@ DEFINE_LUA_FUNCTION(gui_text, "x,y,str[,color=\"white\"[,outline=\"black\"]]")
DEFINE_LUA_FUNCTION(gui_box, "x1,y1,x2,y2[,fill[,outline]]")
{
if(DeferGUIFuncIfNeeded(L))
return 0;
int x1 = luaL_checkinteger(L,1);
int x1 = luaL_checkinteger(L,1); // have to check for errors before deferring
int y1 = luaL_checkinteger(L,2);
int x2 = luaL_checkinteger(L,3);
int y2 = luaL_checkinteger(L,4);
if(DeferGUIFuncIfNeeded(L))
return 0;
int fillcolor = getcolor(L,5,0xFFFFFF3F);
int outlinecolor = getcolor(L,6,fillcolor|0xFF);
@ -3028,11 +3030,12 @@ DEFINE_LUA_FUNCTION(gui_box, "x1,y1,x2,y2[,fill[,outline]]")
// or it can be a preset color like 'red', 'orange', 'blue', 'white', etc.
DEFINE_LUA_FUNCTION(gui_pixel, "x,y[,color=\"white\"]")
{
int x = luaL_checkinteger(L,1); // have to check for errors before deferring
int y = luaL_checkinteger(L,2);
if(DeferGUIFuncIfNeeded(L))
return 0;
int x = luaL_checkinteger(L,1);
int y = luaL_checkinteger(L,2);
int color = getcolor(L,3,0xFFFFFFFF);
if(color & 0xFF)
{
@ -3065,13 +3068,14 @@ DEFINE_LUA_FUNCTION(gui_getpixel, "x,y")
}
DEFINE_LUA_FUNCTION(gui_line, "x1,y1,x2,y2[,color=\"white\"[,skipfirst=false]]")
{
if(DeferGUIFuncIfNeeded(L))
return 0;
int x1 = luaL_checkinteger(L,1);
int x1 = luaL_checkinteger(L,1); // have to check for errors before deferring
int y1 = luaL_checkinteger(L,2);
int x2 = luaL_checkinteger(L,3);
int y2 = luaL_checkinteger(L,4);
if(DeferGUIFuncIfNeeded(L))
return 0;
int color = getcolor(L,5,0xFFFFFFFF);
int skipFirst = lua_toboolean(L,6);
@ -3193,9 +3197,6 @@ DEFINE_LUA_FUNCTION(gui_gdscreenshot, "[whichScreen='both']")
// example: gui.gdoverlay(gd.createFromPng("myimage.png"):gdStr())
DEFINE_LUA_FUNCTION(gui_gdoverlay, "[x=0,y=0,]gdimage[,alphamul]")
{
if(DeferGUIFuncIfNeeded(L))
return 0;
int xStart = 0;
int yStart = 0;
@ -3207,7 +3208,11 @@ DEFINE_LUA_FUNCTION(gui_gdoverlay, "[x=0,y=0,]gdimage[,alphamul]")
yStart = lua_tointeger(L,index++);
}
luaL_checktype(L,index,LUA_TSTRING);
luaL_checktype(L,index,LUA_TSTRING); // have to check for errors before deferring
if(DeferGUIFuncIfNeeded(L))
return 0;
const unsigned char* ptr = (const unsigned char*)lua_tostring(L,index++);
// GD format header for truecolor image (11 bytes)
@ -3924,16 +3929,14 @@ static const struct luaL_reg aggcustom [] =
//
static int gui_osdtext(lua_State *L)
{
int x = luaL_checkinteger(L,1); // have to check for errors before deferring
int y = luaL_checkinteger(L,2);
if(DeferGUIFuncIfNeeded(L))
return 0; // we have to wait until later to call this function because we haven't emulated the next frame yet
// (the only way to avoid this deferring is to be in a gui.register or emu.registerafter callback)
const char *msg;
int x, y;
x = luaL_checkinteger(L,1);
y = luaL_checkinteger(L,2);
msg = toCString(L,3);
const char* msg = toCString(L,3);
osd->addFixed(x, y, "%s", msg);