Is there a possible way to remove the declaration of "laught()" later?
The naive answer is just do
laught = nil
but of course that requires knowing that the script added a Global
variable
named "laught".
If the script writer wants to add his own function (or variable of any
type)
without leaving it hanging around, all he has to do is declare the
variable
to be "local". For instance...
local x = 5
local function laught()
(...)
end
then when the chunk/function created for the script at load time is
garbage
collected, all of these local variables can be garbage collected as well.
----
If you can't "trust" your script writers to make their variables local
then
you will want to employ lua_setfenv. Search the wiki and the list
archives
for "Sandboxing" for a discussion of that.
-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br]On Behalf Of Tharo Herberg
Sent: Tuesday, August 03, 2004 2:47 PM
To: Lua list
Subject: Re: Memory load
Hmm so if i have this script on map "wood"
fucntion laught()
(...)
end
msgbox("This was your last step!!", "Enemy");
laught();
the garbage collector will remove the msgbox and the laught() entry after
running it. but not the funtion.
i want to make some "functions" possible in my maps. so at this point i
dont know why someone should need to make own functions .. but why not.
Is there a possible way to remove the declaration of "laught()" later?
Tharo
Am Tue, 3 Aug 2004 15:32:19 -0500 hat Virgil Smith <Virgil@Nomadics.com>
geschrieben:
Roughly speaking, when you load the script you get a function returned
on
the Lua stack. When you pop it from the Lua stack it will then be a
candidate for garbage collection and in its next pass the garbage
collector
will "remove it". If you don't want this to happen then you will need
to
store a reference to the function in the Lua globals table, or registry.
When you call the function that resulted from loading the script it can
add
things to the globals table and thus consume more memory. For instance,
running the following script segment will add a function and a table to
the
globals table and thus consume some memory...
function Foo()
print("This is a function")
end
Bar = { 1, 2, 3 }
----
However, running this script segment will NOT add anything to the
globals
table, and thus the process of RUNNING this script will not cause any
memory
to be consumed....
print("This script doesn't create or modify any variables")
print("2 times 2 is ", 4)
-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br]On Behalf Of Tharo Herberg
Sent: Tuesday, August 03, 2004 2:06 PM
To: Lua list
Subject: Memory load
Hm ... im new at lea so plz dont kill e for my newbie question.
We want to use lea for smal scriptings in level maps. It runs well,
funtion including was also no problem.
When i load now the script for field xy ... When i load it as function
and
call it from c it stays in ram, right? When i just write scriptcode down
it is cleared from stack and from ram after running it, or?
How can i "remove" functions or code from ram after the player left my
map? I only have 8 MB for everything so this is very importand for me.
thx
Tharo
--
Erstellt mit M2, Operas revolutionärem E-Mail-Modul:
http://www.opera.com/m2/