lua.cr icon indicating copy to clipboard operation
lua.cr copied to clipboard

[WIP] Adding new register_function macro

Open jwoertink opened this issue 4 years ago • 0 comments

Fixes #15

This is currently just WIP because I don't really understand the Lua internals. I know the implementation will need some work as it currently only works with Float64.

With this, you'll be able to define a proc in Crystal, and then name it. Then from Lua you will be able to execute that proc as a function.

lua = Lua.load
Stack.register_function lua, "crystal_add", ->(x : Float64, y : Float64) do
  x + y
end

result = my_stack.run <<-LUA
return crystal_add(1, 2)
LUA

result == 3

jwoertink avatar Aug 29 '21 23:08 jwoertink