Hi Scuri,
The initial funny behavior I had observed is due to a mistake on my part. I've included a new script and lua engine file that are almost the same as the previous ones but without the filedlg part and with the IUP state preserved. I originally did not include the destroy command after leaving iup.MainLoop and the behavior between the close_cb callback function and sending iup.CLOSE via the button action were very different. The dialogs would only 'disappear' when the close_cb callback function were called, but would remain when sending iup.CLOSE (via clicking the 'Done' button) even though the iup.MainLoop would exit. Attempting to close the still visible dialog via the close_cb would crash the engine. What was surprising to me was that running the second script would 'reattach' the original orphaned dialog such that the close_cb could be used on both dialogs. Of course calling destroy or hide on the dialog fixes this problem. What is the preferred way or are they essentially equivalent? Note that the behavior of filedlg is still the same when the IUP state is preserved and is still a problem. Thanks, Brian From: Antonio Scuri <antonio.sc...@gmail.com> Sent: July 27, 2020 9:21 AM To: IUP discussion list. Subject: Re: [Iup-users] Executing multiple IUP lua scripts from within a single lua_State I think we should investigate those funny behaviors. Best, Scuri Em seg., 27 de jul. de 2020 às 09:55, Eves, Brian <brian.e...@nrc-cnrc.gc.ca<mailto:brian.e...@nrc-cnrc.gc.ca>> escreveu: Hi Scuri, I was originally preserving IUP but was noticing some funny behavior when closing dialogs. I had wondered if the fact that I was not cleaning up IUP between scripts was somehow causing the problems. I thought I had mitigated these problems with the current setup where IUP is closed but then I encountered this filedlg issue. I'm running this on a Windows 10 machine using mingw (via MSys2) and gcc to compile. Thanks, Brian ________________________________ From: Antonio Scuri <antonio.sc...@gmail.com<mailto:antonio.sc...@gmail.com>> Sent: July 24, 2020 4:44 PM To: IUP discussion list. Subject: Re: [Iup-users] Executing multiple IUP lua scripts from within a single lua_State I have no idea. WHen I have some time I'll run your test code to see where it is crashing. But why to preserve Lua, CD and IM but not IUP? Best, Scuri Em sex., 24 de jul. de 2020 às 17:03, Eves, Brian <brian.e...@nrc-cnrc.gc.ca<mailto:brian.e...@nrc-cnrc.gc.ca>> escreveu: Hi, I use lua scripts to control hardware for experiments and use a single lua_State to execute different lua IUP scripts so that state information can be retained between scripts. I've encountered a problem that can be replicated using the attached files. The main.cpp file simply creates a lua_State and executes a single script five times in a row. The lua script pops up an iup.filedlg, prints the chosen file name to stdout, and then shows a simple dialog with only one button that ends the script. The first execution of the scripts works fine, but on the second execution the program crashes. If the iup.filedlg is moved into the button callback then the script executes five times without any problems. Am I doing something wrong cleaning IUP between running the scripts? Thanks for your help, Brian _______________________________________________ Iup-users mailing list Iup-users@lists.sourceforge.net<mailto:Iup-users@lists.sourceforge.net> https://lists.sourceforge.net/lists/listinfo/iup-users _______________________________________________ Iup-users mailing list Iup-users@lists.sourceforge.net<mailto:Iup-users@lists.sourceforge.net> https://lists.sourceforge.net/lists/listinfo/iup-users
#include <iostream> #include <fstream> #include <vector> #include <string> extern "C" { #include "iup.h" #include "iupcontrols.h" #include "im.h" #include "cd.h" #include "lua.h" #include "lauxlib.h" #include "lualib.h" #include "iuplua.h" #include "iupluacontrols.h" #include "iuplua_plot.h" #include "imlua.h" #include "cdlua.h" #include "cdluaiup.h" #include "cdluaim.h" } std::string LoadFile (const std::string& filename) { std::ifstream ifs(filename.c_str(), std::ios::in | std::ios::binary | std::ios::ate); if (ifs.fail()) { return std::string(); } std::ifstream::pos_type fileSize = ifs.tellg(); if (fileSize < 0) { return std::string(); } ifs.seekg(0, std::ios::beg); std::vector<char> bytes(fileSize); ifs.read(&bytes[0], fileSize); return std::string(&bytes[0], fileSize); } int main (int argc, char* argv[]) { lua_State* L = luaL_newstate(); // creates a new lua state luaL_openlibs(L); // Load Lua libraries imlua_open(L); // Load IM libraries cdlua_open (L); // Load CD libraries cdluaim_open (L); // Load joint IM&CD libraries cdluaiup_open (L); iuplua_open (L); // Load IUP libraries iupcontrolslua_open(L); // Load IUP controls library iup_plotlua_open (L); // Load IUP plot library if (argc < 2) { return 1; } std::string scriptname(argv[1]); // load script std::string script = LoadFile(scriptname); for (int i =0; i < 5; ++i) { int rstate = luaL_loadbuffer (L, script.c_str(), script.size(), scriptname.c_str()); if (rstate != 0) { // error const char* message = lua_tostring (L, -1); std::cout << message; return 1; } rstate = lua_pcall (L, 0, 0, 0); if (rstate != 0) { // error const char* message = lua_tostring (L, -1); std::cout << message; return 1; } // force collection of garbage lua_gc (L, LUA_GCCOLLECT, 0); } iuplua_close (L); imlua_close (L); cdlua_close (L); lua_close (L); return 0; }
test.lua
Description: test.lua
_______________________________________________ Iup-users mailing list Iup-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/iup-users