-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
This commit is contained in:
Adrien Destugues 2009-11-24 17:56:05 +00:00
parent 73ca64c9dc
commit 0be1f7bff1

View File

@ -195,6 +195,7 @@ void Button_Brush_Factory(void)
if (clicked_button == 2) // Run the script if (clicked_button == 2) // Run the script
{ {
lua_State* L = lua_open(); lua_State* L = lua_open();
char* message;
lua_register(L,"putbrushpixel",L_PutBrushPixel); lua_register(L,"putbrushpixel",L_PutBrushPixel);
lua_register(L,"getbrushpixel",L_GetBrushPixel); lua_register(L,"getbrushpixel",L_GetBrushPixel);
@ -211,13 +212,27 @@ void Button_Brush_Factory(void)
// For debug only // For debug only
// luaL_openlibs(L); // luaL_openlibs(L);
luaopen_math(L);
strcat(scriptdir, Get_item_by_index(&Scripts_list, strcat(scriptdir, Get_item_by_index(&Scripts_list,
scriptlist->List_start + scriptlist->Cursor_position) scriptlist->List_start + scriptlist->Cursor_position)
-> Full_name); -> Full_name);
if (luaL_loadfile(L,scriptdir) != 0) 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) 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); lua_close(L);
} }