The functon require no succeed two Times
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 8
- Joined: Wed Jul 15, 2020 10:56 pm
The functon require no succeed two Times
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?
-
- Party member
- Posts: 563
- Joined: Wed Oct 05, 2016 11:53 am
Re: The functon require no succeed two Times
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":
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:
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.
Code: Select all
print(package.loaded["myfile"]) -- prints nil
require("myfile")
print(package.loaded["myfile"]) -- prints something like table: 0x0026f0a8
Code: Select all
package.loaded["myfile"] = nil -- clears the cache for "myfile"
require("myfile") -- because the cache was emptied, require loads the file again
-
- Prole
- Posts: 8
- Joined: Wed Jul 15, 2020 10:56 pm
Re: The functon require no succeed two Times
Eeeeee i try verry, but all objects create self clone, i try use dofile but no know how find the path complete
-
- Party member
- Posts: 563
- Joined: Wed Oct 05, 2016 11:53 am
Re: The functon require no succeed two Times
Can you post your code? It'll make it easier to help.
-
- Prole
- Posts: 8
- Joined: Wed Jul 15, 2020 10:56 pm
Re: The functon require no succeed two Times
Sorry, i am resolved, its existed two archiver for restart
Who is online
Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Google [Bot] and 3 guests