mirror of
https://github.com/kanaka/mal.git
synced 2024-09-20 10:07:45 +03:00
crystal: implement mal in Mal module
This commit is contained in:
parent
85c1b0c0d8
commit
2c436e30c0
@ -8,15 +8,18 @@ lib LibReadline
|
||||
fun add_history(line : UInt8*)
|
||||
end
|
||||
|
||||
def my_readline(prompt = "")
|
||||
line = LibReadline.readline(prompt)
|
||||
if line
|
||||
LibReadline.add_history(line)
|
||||
String.new(line)
|
||||
else
|
||||
nil
|
||||
end
|
||||
ensure
|
||||
LibC.free(line as Void*) if line
|
||||
end
|
||||
module Mal
|
||||
|
||||
def my_readline(prompt = "")
|
||||
line = LibReadline.readline(prompt)
|
||||
if line
|
||||
LibReadline.add_history(line)
|
||||
String.new(line)
|
||||
else
|
||||
nil
|
||||
end
|
||||
ensure
|
||||
LibC.free(line as Void*) if line
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -21,6 +21,6 @@ def rep(x)
|
||||
read(eval(print(x)))
|
||||
end
|
||||
|
||||
while line = my_readline("user> ")
|
||||
while line = Mal::my_readline("user> ")
|
||||
puts rep(line)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user