Page 1 of 1

The functon require no succeed two Times

Posted: Wed Jun 02, 2021 10:37 am
by Jose_antonio_920
Frist i not know speak english, my english is bad. In my code i use one require in one archive, but o try reset the archive Using require but no suceed, Nothing change, o try use setmetatable for create one clone but no succeed. What I can do?

Re: The functon require no succeed two Times

Posted: Wed Jun 02, 2021 2:49 pm
by MrFariator
When you load a file with require, it caches the result so to avoid duplication of work on subsequent requires to the same file. The files loaded with require can be accessed via the global "package.loaded":

Code: Select all

print(package.loaded["myfile"]) -- prints nil
require("myfile")
print(package.loaded["myfile"]) -- prints something like table: 0x0026f0a8 
So, if you really want to empty the cache and require a file again, you could set the corresponding entry in package.loaded to nil:

Code: Select all

package.loaded["myfile"] = nil -- clears the cache for "myfile"
require("myfile") -- because the cache was emptied, require loads the file again
However, I wouldn't necessarily recommend this approach, as messing with require cache seems dirty to me. Perhaps you could use something like love.filesystem.load for this purpose instead, or make your file return a function that you can simply call to create an instance of whatever class or data the file represents? Depends on what your exact use case is, I reckon.

Re: The functon require no succeed two Times

Posted: Thu Jun 03, 2021 3:20 pm
by Jose_antonio_920
Eeeeee i try verry, but all objects create self clone, i try use dofile but no know how find the path complete

Re: The functon require no succeed two Times

Posted: Thu Jun 03, 2021 4:37 pm
by MrFariator
Can you post your code? It'll make it easier to help.

Re: The functon require no succeed two Times

Posted: Mon Jun 14, 2021 3:46 pm
by Jose_antonio_920
Sorry, i am resolved, its existed two archiver for restart