lua-users home
lua-l archive

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

> This is bad for two reasons.
> First, there are the memory issues you describe. A different copy of the
> function is created each time, and remains until the garbage collector runs.

Ah so if I force the garbage collector to run the memory problems
should go away ? I'll look into that right now.

> Even more inneficiently, however, this means that lua has to parse and
> compile your script each time you iterate through the loop! This is obviously
> quite a waste.

I do realise this, I was only giving an example there, the script that
is being parsed is user supplied (run-time). And it is something different all
the time. But it can be the same and it can be triggered very often
very fast. ( My program reacts to infrared input for example ).
Storing the bytecode is a second step that will be done in
the future.

> For things such as this, I suggest you not use dostring. Instead, before the
> loop use something like "loadstring" (I'm afraid I'm not in front of my API
> reference right now), which will stick the function on the stack. Then, in
> your loop, each time call:

hmm,.. interesting, but probably not doable since I have no knowledge
of what the user wants to do in the script. ( it doesn't have to be a
function ).

Thanks for your suggestions!!