Closed kojix2 closed 1 year ago
I decided to look into Anyolite because I thought it might be possible to write a plugin for https://github.com/kojix2/chatgpt-cli in Ruby. The Anyolite example is written with the goal of using Crystal objects from Ruby, but my goal is to add a small amount of Ruby to the Crystal code and evaluate it at runtime. I think this small difference makes it difficult for me to find a way to use it. Thank you.
Yep, that's a bug.
For some reason the variable name is not correctly translated over to Ruby, I will look into this.
Should be fixed now in the newest commit to the main branch.
For some reason, the mruby and Ruby API are inconsistent in their use of symbols and strings for the variable accessor methods, and I messed it up at some point :-)
Note that you have to recompile Anyolite (specifically the glue files) again after obtaining the newest commit (this can be done using rake recompile_glue
from the Anyolite directory if you don't want to compile the whole mruby library again).
Also you might want to explicitly add the $
to variables, just for consistency (since mruby doesn't do this automatically).
Thanks @Hadeweka
I have confirmed that the last commit on Github main branch works for me. My first try failed with the following error:
Showing last frame. Use --error-trace for full trace.
In /usr/share/crystal/src/regex/pcre.cr:99:34
99 | Regex::MatchData.new(self, @re, str, byte_index, ovector, @captures)
^--
Error: expected argument #2 to 'Regex::MatchData.new' to be ::Pointer(LibPCRE2::Code), not LibPCRE::Pcre
Overloads are:
- Regex::MatchData.new(regex : ::Regex, code : ::Pointer(LibPCRE2::Code), string : String, pos : Int32, ovector : ::Pointer(LibC::SizeT), group_size : Int32)
I remember the announcement that the latest crystal 1.8.0-dev uses libpcre2. So I got the latest crystal from GitHub and compiled it. Then it worked well.
I appreciate your help :+1:
Can you tell me, which Crystal version exactly you used before?
If it was a more recent full release version, this should not have happened.
My previous crystal version is 1.7.3
To confirm this behavior, I recompiled Crystal 1.7.3 again and got a different error from the first time... Umm
Showing last frame. Use --error-trace for full trace.
There was a problem expanding macro 'getter'
Code in /usr/local/share/crystal/src/regex.cr:239:3
239 | getter options : Options
^
Called macro defined in macro 'macro_139846050773632'
117 | macro getter(*names, &block)
Which expanded to:
> 2 |
> 3 |
> 4 | @options : Options
^-------
Error: instance variable '@options' of Regex was not initialized directly in all of the 'initialize' methods, rendering it nilable. Indirect initialization is not supported.
But I will move to 1.8.0 soon. I don't care if 1.7.X does not work. Thanks.
Hi! Thank you for maintaining this project. But I need help. I want to call Ruby code from Crystal. However, I needed help figuring out how to pass the Crystal object to Ruby and the Ruby object to Crystal.
This may seem like a simple question, but I have read the README and the Wiki. I also read some of the source code and worked on the problem for several hours, but could not solve it. (What I want you to understand is that I'm not rushing to open a problem a few minutes after I see the project. I have seen a lot of macros do type conversions and call the appropriate RbCore functions for a bit, but it is too difficult to figure it all out on my own. So I decided to ask for help.)
The easiest seemed to be to exchange global variables. So I wrote the code below
But even that did not work. This creates a kind of strange global variable that looks like this
What am I missing?