lua-users home
lua-l archive

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


> First, when I use "print" in my Lua scripts, it causes
> my entire program to crash. I typically use it for
> debugging and sometimes I forget to remove them when I
> test in Windows. I did discover that if I define my
> own print function in C (which just calls printf) and
> call it from Lua, my program doesn't crash. Can
> somebody explain this to me, and more importantly, is
> there a way I can get Windows to work with print?

You did not mention what type of Windows application you're working on, but
I've noticed similar problems when incorporating Lua 4.0.x into GUI
applications.

Console applications should work just fine, since print-s just end up on
stdout and any errors Lua spits out go to stderr. The situation seems to be
different with GUI apps, though.

I'm mostly using Borland's C++ Builder (instead of MSVC), but the net effect
seems the same: whenever something's sent to either stdout or stderr, the
host application crashes during exit. I haven't really had the time to
research the precise cause of this problem, so if anyone can shed some light
I'd love to hear about it.

> My second problem is similar to the first. When ever I
> have an error in my Lua script (or something where Lua
> triggers an error), my entire program crashes in
> Windows.

The solution I found is similar to the one you already described: just make
sure you register your own print replacement (for debugging &c.) and[!] a
function to handle _ALERT. The latter is the function that gets called
whenever Lua (v4) outputs any errors. I found that redefining these 2
functions prevented my Lua GUI host app from taking unexpected nose dives.

I believe the (error handling) situation is somewhat different for Lua 5. I
haven't really made the jump yet, so perhaps someone else can enlighten us
there.

I hope this helps,

Ashwin.