From 0be1f7bff13f11967a6044c93cd0afccb079eefc Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Tue, 24 Nov 2009 17:56:05 +0000 Subject: [PATCH] -Load Lua's math library when running factory scripts, as this makes them a lot more useful (sin, cos, ...) -Don't crash when Lua fails loading a script but does not return an error message. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1223 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- factory.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/factory.c b/factory.c index 32142429..d2a7d9ed 100644 --- a/factory.c +++ b/factory.c @@ -195,6 +195,7 @@ void Button_Brush_Factory(void) if (clicked_button == 2) // Run the script { lua_State* L = lua_open(); + char* message; lua_register(L,"putbrushpixel",L_PutBrushPixel); lua_register(L,"getbrushpixel",L_GetBrushPixel); @@ -211,13 +212,27 @@ void Button_Brush_Factory(void) // For debug only // luaL_openlibs(L); + luaopen_math(L); + strcat(scriptdir, Get_item_by_index(&Scripts_list, scriptlist->List_start + scriptlist->Cursor_position) -> Full_name); if (luaL_loadfile(L,scriptdir) != 0) - Verbose_error_message(lua_tostring(L, 1)); + { + message = lua_tostring(L, 1); + if(message) + Verbose_error_message(message); + else + Warning_message("Unknown error loading script!"); + } else if (lua_pcall(L, 0, 0, 0) != 0) - Verbose_error_message(lua_tostring(L, 1)); + { + message = lua_tostring(L, 1); + if(message) + Verbose_error_message(message); + else + Warning_message("Unknown error loading script!"); + } lua_close(L); }