lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


OK thanks.  I’ve taken your advice and no longer auto-open IUP, so henceforth scripts that use IUP will have to use a require statement.  This doesn’t solve all problems.  It’s still the case that closing an IUP dialog following an error is likely to close the application, as far as I can see.  But at least it only happens if there’s an error; and this way users at least get to see the error message.

 

Simon

 

From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On Behalf Of Antonio Scuri
Sent: 28 March 2019 1:38 PM
To: Lua mailing list
Subject: Re: Errors in IUP scripts are causing my application to shut down

 

  Hi Simon,

 

  I don't have a solution but a few comments.

 

  I wouldn't call iuplua_close for every script, if this is what you are doing. Using require is the recommended option. But notice that does not call IupClose anywhere. 

 

  I don't see why an error in Lua code would close an IUP dialog. If this happen before could be an error in older IupLua error management. The current IupLua error dialog allow 3 actions: Copy the error report to the clipboard, Continue with the execution (the Lua script will abort but will not close any dialogs), and Exit the application. You can replace this dialog with your own version that can close your dialogs.

 

Best,

Scuri

 

  

 

Em qua, 27 de mar de 2019 às 17:39, Simon Orde <SimonOrde@family-historian.co.uk> escreveu:

Hi – My Visual C++ app uses Lua to run scripts.  Following various upgrades, I now have a problem with scripts that use IUP.  If an error occurs in an IUP script, what usually happens is that instead of displaying a sensible error message, it shuts down my application somehow.  This is a new problem that has only started happening since I upgraded  my application from Visual Studio 2010 to 2017.  When I upgraded my compiler, I also upgraded from Lua 5.1 to Lua 5.3.5 and from IUP 3.9 to IUP 3.26.  That required a number of changes to get everything working.  I’ve manged to overcome most issues, but this one is still unresolved.

 

The following simplified script illustrates the problem:

 

text = iup.multiline{expand = "YES"}

dlg = iup.dialog{text; title="Simple Dialog",size="QUARTERxQUARTER"}

dlg:show()

 

t = {}

t.force_error()

 

iup.MainLoop()

 

The script puts up an IUP dialog and then forces an error with the line "t.force_error()".  The “iup.MainLoop()” line is never reached (for interest, if I move the “t.force_error()” line before the dlg:show” line, or after the “iup.MainLoop()” line, the error does not force my application to shut down).

 

I run Lua scripts from my C++ application using the Lua API.   For historical reasons, I use run-time dynamic linking.  I use ::LoadLibrary to load lua53.dll and iuplua53.dll, and make numerous ::GetProcAddress calls to get the addresses of the various functions I need to call.  I had to make some changes to cope with incompatibilities between Lua 5.3 and Lua 5.1, but it mostly seems to be working now.  I call the function iuplua_open in the iuplua53.dll before running the script.  I then run the script by calling lua_load followed by lua_pcallk ( I call the latter with parameters (L, 0, LUA_MULTRET, 0, 0, NULL)).  When the script hits the error, I get an error return from lua_pcallk.  Normally, at this point I would call iuplua_close.  However, if I do that, my application exits after the function returns (the ‘ExitInstance’ method of my application object gets called).

 

I can of course test for an error return from lua_pcallk and simply not call iuplua_close if the former returns an error.  But if I do that, the IUP dialog is left on-screen.  If I click on its Close button, my application immediately closes down.

 

I tried taking out the calls to iuplua_open and iuplua_close, and adding the line “require iuplua” at the start of my script (e.g. the script above), with a suitable cpath set up (I came across some issues in the process, which I will probably post about separately, but never mind that for now).  This worked up to a point.  When the line “t.force_error()” was hit, the script ended with an error and my application stayed open.  But unfortunately so did the IUP dialog.  And if I closed it manually, my application also closed.

 

I never had this problem under the old build of my application using Lua 5.1 and IUP 3.9.  If I run the script shown above in that version, when the error is forced, the IUP dialog is immediately closed, and lua_pcall (as it then was) returns an error; but my application does not shut down. 

 

Can anyone suggest a solution?  All help much appreciated.


Simon