Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add editor button to force reload the current module #22

Closed
ngwese opened this issue Mar 12, 2018 · 2 comments
Closed

add editor button to force reload the current module #22

ngwese opened this issue Mar 12, 2018 · 2 comments
Labels

Comments

@ngwese
Copy link
Member

@ngwese ngwese commented Mar 12, 2018

when developing a (lua) module changes don't get picked up if the module has been already been loaded via require.

it is possible to force a module to get reloaded by setting package.loaded.<module_name> = nil then calling require '<module_name>'

to facilitate module development it might be nice to have button in the editor which sends this to the repl (after a save), or by making the save button more smart...

@pq
Copy link
Collaborator

@pq pq commented Jun 10, 2018

following up on a conversation on lines, as @catfact pointed out elsewhere a work-around is to explicitly un-load the module (to the extent that you can).

the basic idea can be expressed in a helper function, like this:

function reload(module_name)
  if (package.loaded[module_name] ~= nil) then
    package.loaded[module_name] = nil
    _G[module_name] = nil
  end
  return require(module_name)
end

that you use in your script like this:

-- reload, really.
local foo = reload("foo")

in the simplest cases this works well enough during development.

(FWIW: i put this function in a utility library that i use while writing scripts; works great.)

@ngwese
Copy link
Member Author

@ngwese ngwese commented Mar 8, 2020

this is largely no longer an issue now that include(...) is a thing

@ngwese ngwese closed this Mar 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants