Comments (13)
I once built a proof of concept for C++ to make this possible: https://github.com/inspector-repl/inspector
from crystal-libraries-needed.
@jwoertink You could try using fancyline instead of libreadline.
from crystal-libraries-needed.
AFAIK readline
(or fancyline
) allows you to only interrupt execution and read/evaluate an interactive command (aka repl). binding.pry
in ruby is much more than just readline
. Let's look at the example:
require 'pry'
class A
end
def ruby_method1
end
def ruby_method2(a, b)
binding.pry # <--- execution stopped here
end
ruby_method2 3, "a"
[1] pry(main)> a
=> 3
[2] pry(main)> b
=> "a"
[3] pry(main)> A.new
=> #<A:0x007f93e06910d8>
[4] pry(main)> ruby_method1
=> nil
[5] pry(main)> c
NameError: undefined local variable or method `c' for main:Object
from (pry):7:in `ruby_method2'
here pry
knows the execution context it is running in, so it can show you the values of method args, create an instance of available class A
and call a method. Also, it knows that there is no var c
, for example. This is achieved by the Binding
class in ruby:
Objects of class Binding encapsulate the execution context at some particular place in the code and retain this context for future use. The variables, methods, value of self, and possibly an iterator block that can be accessed in this context are all retained. Binding objects can be created using Kernel#binding, and are made available to the callback of Kernel#set_trace_func.
If we could have something similar in Crystal, it would be really easy to implement analog of binding.pry
. Take a look at the first pry's release in ruby: https://github.com/pry/pry/blob/4fcf81b97601945945f43311532c164a93b44d7c/lib/pry.rb
But creating Binding
may look like a challenge for Crystal...
from crystal-libraries-needed.
I made a pure crystal library that doesn't rely on readline called Term::Reader if anyone would like to use that for something like this. Not sure about the rest of the
pry
functionality though.
@watzon that's completely off-topic
from crystal-libraries-needed.
ICR exists. There's obviously some differences since crystal is a compiled language. I don't think it lets you use vim inside of it like pry.
from crystal-libraries-needed.
Honestly, I'd be happy with it if I could view source code or documentation for a class/module/method. Being able to "cd" into a construct (whether class or instantiated object) is incredibly helpful when debugging.
from crystal-libraries-needed.
I actually started working on a way to do this in ICR. The libreadline library actually has a lot of really useful features that would help us to achieve this. Also, somehow integrating lldb would as well. The issue with the readline is that it's lacking in crystal. I made an issue for one part crystal-lang/crystal#4067 which is macOS related, but that prevents me from moving forward.
I'd like to tackle this again if anyone wants to jump on board with me!
from crystal-libraries-needed.
from crystal-libraries-needed.
Yeah, that's what they say; however, similar code runs in other languages. I don't think it's a readline issue, but I don't know the library well enough to be 100% sure.
from crystal-libraries-needed.
@elorest For example Haskell is compiled too and there is really pretty interactive env for that. What is different from Crystal?
from crystal-libraries-needed.
@schovi GHC for Haskell has two modes, compiled and interpreted. runghc
and ghci
use the latter.
from crystal-libraries-needed.
@citizen428 thanks for explanation!
from crystal-libraries-needed.
I made a pure crystal library that doesn't rely on readline called Term::Reader if anyone would like to use that for something like this. Not sure about the rest of the pry
functionality though.
from crystal-libraries-needed.
Related Issues (20)
- Apache Arrow Support HOT 1
- walkdir library HOT 7
- Web scraper HOT 3
- Suggestion: port gem mimemagic from Ruby for significant (and fully platform agnostic) MIME type coverage
- Push notification service
- Port of impersonator gem
- fastimage shard HOT 3
- XMPP / Jabber client shard HOT 2
- Font renderer HOT 7
- Relational Algebra
- Math parser / evaluator HOT 6
- Flashtext port
- Tokyo Tyrant (Tokyo Cabinet server) HOT 4
- Python to Crystal converter HOT 3
- Data-parallelism library
- Algorithmic Trading Library
- integration with a browser recording library: playwright library / puppeteer library / something similar HOT 5
- A rewrite of Centrifuge use crystal
- Kubernetes API HOT 2
- RDF library
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crystal-libraries-needed.