franko / gsl-shell

GSL library shell based on LuaJIT2
http://franko.github.io/gsl-shell/
GNU General Public License v3.0
92 stars 12 forks source link

'Use' imports to the wrong level when called from a co-routine #17

Closed pkulchenko closed 10 years ago

pkulchenko commented 10 years ago

Francesco,

The following fails with GSL-shell 2.3.1:

coroutine.resume(coroutine.create(function()
  use 'math'
  print(pi)
end))

pi is printed as nil. I think the use() function has to be modified to use level 2 instead of 3:

function use(...)
   local level = debug.getinfo(2, "") and 2 or 0 --<-- use level 2
   local env = new_env()
   env.use(...)
   setfenv(level, env)
end

This affects debugging in ZeroBrane Studio as it's using coroutines to run debugging (for reference: pkulchenko/ZeroBraneStudio#239).

franko commented 10 years ago

Ok, it seems that 2 is more correct.

Problem fixed in master branch with commit https://github.com/franko/gsl-shell/commit/7d48dfd96e0bbbc68fda70347e2e83b62ed83a55. The 2.3.2 release may come quite soon, I've already quite a lot of fixes and enhancements.

Thank you for reporting that.

Francesco