lua-users home
lua-l archive

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


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