• You've discovered RedGuides, an EverQuest multi-boxing and scripting community 🧙‍♀️⚙️. We want you to play several EQ characters at once, come join us and say hello! 👋

  • A TLP without truebox has thawed (Very Vanilla ready)
    Frostreaver

Question - Force reload of required lua script

Soandso2

Well-known member
Joined
Mar 13, 2023
RedCents
937¢
Is there any way to force reload a required Lua?

Example:
foo.Lua contains a require("bar")

While foo.Lua is running, I make a change to bar.Lua. Is there anyway to force reload bar.Lua other than exiting and reloading foo.Lua?
 
Considering the lack of replies to the question, I presume the answer is "No, you cannot reload a required/included script by any other means than terminating the master script and running it again".
 
I think the deeper question is why would you need to do this. I can't imagine the need to completely restart a script unless it's not designed correctly. Does the script load something on start that you later need to reload for example? Then I would have a bind to reload that data rather than restart the script. XY problem here perhaps?
 
I think the deeper question is why would you need to do this. I can't imagine the need to completely restart a script unless it's not designed correctly. Does the script load something on start that you later need to reload for example? Then I would have a bind to reload that data rather than restart the script. XY problem here perhaps?
Master script is stand-alone and works as intended. Included script is an addition with code that you do not want to include in the master script - it is in development and you might be tweaking or rewriting parts. You make a change and you want to see if the change worked. It is not so much a "why would you want to", but a "is it at all possible to" question.
 
Yes, it's possible. I still contend this is an XY problem.

[CODE lang="Lua" title="This is our "working as intended script""]local mq = require("mq")
while true do
print("lua_one running...")
mq.delay(1000)
end[/CODE]

[CODE lang="Lua" title="This is our testing script that will stop and restart the first script"]local mq = require("mq")

print("lua_two running...")

print("stopping lua_one...")
mq.cmd("/Lua stop lua_one")
mq.delay(2000)

print("restarting lua_one...")
mq.cmd("/Lua run lua_one")[/CODE]

If you run these you'll see that script one will print out "lua_one running" every second...
Running the second one will stop, wait 2 seconds and then start (restart) the lua_one script.
 
i think you misunderstood the question coldblooded, he wants to know if you can make change to a required Lua file, and then have the main script reload the changed Lua file, remember required Lua files dont run, they just contain code, like the write.Lua by knightly.
 
Oh, sorry! Thanks for the explanation Kaen.

Yes, it's still possible. Just "depends" on how much control you have over the main script file.

Basically, it works like this

[CODE lang="Lua" title="Original"]local mymodule = require("mymodule")


-- I hate my module, let me reload it!
package.loaded["mymodule"] = nil
mymodule = require("mymodule")[/CODE]
 
Oh, sorry! Thanks for the explanation Kaen.

Yes, it's still possible. Just "depends" on how much control you have over the main script file.

Basically, it works like this

[CODE lang="lua" title="Original"]local mymodule = require("mymodule")


-- I hate my module, let me reload it!
package.loaded["mymodule"] = nil
mymodule = require("mymodule")[/CODE]
Aaaha there we go. Thank you so very much. :)
 
Question - Force reload of required lua script

Users who are viewing this thread

Back
Top
Cart