Skip to content

Conversation

@jwoertink
Copy link

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

{% end %}

# push result to stack
LibLua.pushnumber(state, {{ proc.body }})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming if one of the proc.args is a String, then we would call LibLua.pushstring here? But that expected a Pointer(UInt8) to be passed in... But also, what happens if the first arg is a String, and the second is a number? Does the value of each arg need to be pushed separately?

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

Successfully merging this pull request may close these issues.

Crystal callback

1 participant