lua-users home
lua-l archive

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



On 4-Feb-05, at 9:03 PM, David Given wrote:

For example, if my C plugin runs out of memory, what's it supposed to do? Currently, it's supposed to do something like 'lua_error("out of memory")'.
Unfortunately, this won't be caught be code that is expecting
'lua_error("memory allocation failure")' or 'lua_error("malloc() returned NULL")'... the Lua core has a standard term for this, and a helper function
to throw it, but it's not defined.

That's a good point. Pushing a string onto the Lua stack might
called malloc() which would not be a good idea right after a malloc()
failure. The Lua core goes to some trouble to ensure that the string
"out of memory" does actually exist in the string table so as to avoid
that; it would be useful to export some interface.

On the other hand, if you were able to write C plug-ins whose only
memory allocation were through the Lua userdata API (and that is
possible in some cases), then you can simply not worry about
memory allocation, and you might be able to take advantage of
Lua's garbage collection to boot. Unfortunately, this is not
easy to do when interfacing with external libraries, even ones
which allow you to specify a custom allocator.

However, don't get me started on the massive bloatedness which
results from i18n libraries. (How many copies of the Estonian
translation for "File not found" do I really need on my hard
drive?)