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

Error: too many local variables for binding (mruby limitation) #145

Closed
buty4649 opened this issue Jan 10, 2024 · 5 comments
Closed

Error: too many local variables for binding (mruby limitation) #145

buty4649 opened this issue Jan 10, 2024 · 5 comments

Comments

@buty4649
Copy link
Owner

mrubyの制約としてBindingできるローカル変数に上限があるようだ。

❯ ruby -e '50.times {|n| p n}' | rf -q 'a = 1'
Error: too many local variables for binding (mruby limitation)

https://github.com/mruby/mruby/blob/master/src/proc.c#L456

@buty4649
Copy link
Owner Author

↓のようなことができないのがつらい

❯ ruby -e '50.times {|n| p n}' | rf -q 'h||=Hash.new(0); h[_]+=1'
Error: too many local variables for binding (mruby limitation)

@buty4649
Copy link
Owner Author

https://github.com/mruby/mruby/blob/master/src/proc.c#L437-L448 あたりを見るとデフォルトでは50が最大っぽい。
ただし、MRB_IREP_LVAR_MERGE_LIMITが定義されている場合最大240までは拡張できそう。

@buty4649
Copy link
Owner Author

239行(239ループ)まではいけるようになった

$ seq 1 239 | rf -q 'v = 0'
#=> エラーにならない

$ seq 1 240 | rf -q 'v = 0'
Error: too many local variables for binding (mruby limitation)

@buty4649
Copy link
Owner Author

この問題を回避するにはグルーバル変数を使う必要がある

$ seq 1 1000 | rf -q '$s+=1; at_exit{p $s}'
1000

@buty4649
Copy link
Owner Author

fixed mruby/mruby#6275

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant