Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

CodeZ

How to unload script from Lua?

This topic is 5570 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible to UnLoad a script from luas memory? If not how many functions can you load into memory with lua_dofile before something bad happends Thanks!

Share this post


Link to post
Share on other sites
Advertisement
well theoretically concerning the maximum function you can load into a lua state should be limited only by your ram (and i think youll have to sit quite a lot to write enough scripts to fill that up)

but on the other hand id guess it will be slower for every function cos the parser/interpreter has to search for the right function each time one is called

besides that it should be no problem (although im absolutely no expert with lua)


mfg Phreak
--
"Input... need input!" - Johnny Five, Short Circuit.

Share this post


Link to post
Share on other sites
Undoing a complete script (read more than one function call and so on...) is quite impossible.

If you only want to remove a parsed function or variable, simply set it to "nil". More difficult: get the global table and remove the unwanted entries (talking Lua 5.0)

Share this post


Link to post
Share on other sites
Thanks!

So you must have unique names on all lua functions? You can''t have 2 funtions in diffrent script files that have the same name? That is not very good.

The only way I can think of, to use functions with same names, is to have a unique lua_State* for each file and manually copy all global funtions to this state, is that how it is supposed to work?

Share this post


Link to post
Share on other sites
I''m not sure but i think in every scope you can have only one variable/function with the same name. You can however have functions with the same names in different tables (just like object member functions). Lua also does not allow function overloading (same name, different params).

When you let two scripts parse when both define a function with the same name, the second script will redefine the function.

Share this post


Link to post
Share on other sites
The "standard" method of dealing with it, is to put all of the functions into a table for that library. If you then want to remove the script, you can do it by removing the library''s table from the global table (setting it to nil). This will also prevent name conflicts, as the functions in one table will not be replaced by functions of the same name in a different table.

I suggest you read Lua Technical Note 7, at www.lua.org (to be specific: http://www.lua.org/notes/ltn007.html)

John B

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!