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

Fix take over file scope variables with mruby and mirb command #4933

merged 5 commits into from Sep 10, 2020


Copy link

  • Add mrbc_cleanup_local_variables() function with MRB_API
  • In mirb command, the _ variable is defined after the -r switch

Copy link

shuujii commented Jan 20, 2020

The following example doesn't seem to work as expected:


# a.rb
a = 1
A = ->{a}
# b.rb


$ bin/mruby -r ./a.rb b.rb


$ ruby -r ./a.rb b.rb

Copy link
Contributor Author

😿 That's true.

I was worried and tried mrbc, and it was the same without applying this patch.

% bin/mrbc a.rb
% bin/mrbc b.rb
% bin/mruby -br a.mrb b.mrb

It seems that can deal with it using REnv, but I may not be able to handle it...

Copy link

matz commented Jan 21, 2020

@dearblue It works as CRuby (1) on my box.

Copy link
Contributor Author

On FreeBSD 12.1/amd64, after slightly modifying mrbgems/mruby-print/mrblib/print.rb of mruby-head (59464f3), the result is as follows.

% git checkout --detach origin/master
HEAD is now at 59464f35 Merge pull request #4935 from mimaki/delete-duplicated-Array-delete_if
% echo 'a,b,c,d,e,f,g,h,i,j,k,l,m,n=1,2,3,4,5,6,7,8,9,10,11,12,13,14; A=->{[a,b,c,d,e,f,g,h,i,j,k,l,m,n]}' >> mrbgems/mruby-print/mrblib/print.rb
% rake -m clean all
% bin/mruby -e 'a=999; b=123; c="ccc"; p'
[999, 123, "ccc", main, main, nil, 999, 123, "ccc", main, main, nil, 999, 123]

Copy link
Contributor Author

I fixed the problem pointed out by @shuujii and the problem with mruby binary.

@dearblue dearblue closed this Jan 29, 2020
Copy link
Contributor Author

I made a mistake.

@dearblue dearblue reopened this Jan 29, 2020
@matz matz merged commit c27e451 into mruby:master Sep 10, 2020
matz added a commit that referenced this pull request Sep 10, 2020
@dearblue dearblue deleted the variables branch September 24, 2020 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

3 participants