lua

Lua bridge lua bindings
0.3.0 Latest release released

lua.cr

CI

Crystal bindings to Lua. Supports Lua 5.4 and higher (including Lua 5.5).

Installation

Lua development libraries must be installed on your system:

# macOS
brew install lua

# Ubuntu/Debian
sudo apt install liblua5.4-dev

# Arch Linux
sudo pacman -S lua

# Fedora
sudo dnf install lua-devel

Then add this to your application's shard.yml:

dependencies:
  lua:
    github: veelenga/lua.cr

Usage

First you need to require Lua:

require "lua"

Then you can run a chunk of Lua code:

Lua.run %q{
  local hello_message = table.concat({ 'Hello', 'from', 'Lua!' }, ' ')
  print(hello_message)
} # => prints 'Hello from Lua!'

Or run a Lua file and obtain results:

p Lua.run File.new("./examples/sample.lua") # => 42.0

Or even evaluate a function and pass arguments in:

lua = Lua.load
sum = lua.run %q{
  function sum(x, y)
    return x + y
  end

  return sum
}
p sum.as(Lua::Function).call(3.2, 1) # => 4.2
lua.close

More features coming soon. Try it, that's fun :)

Contributing

  1. Fork it https://github.com/veelenga/lua.cr/fork
  2. Create a feature branch git checkout -b my-new-feature and implement your feature
  3. Run tests crystal spec and format code crystal tool format
  4. Commit your changes git commit -am 'Add some feature'
  5. Push to the branch git push origin my-new-feature
  6. Create a new Pull Request
lua:
  github: veelenga/lua.cr
  version: ~> 0.3.0
License MIT
Crystal >= 1.0.0

Authors

Dependencies 0

Development Dependencies 1

  • ameba ~> 1.6
    {'github' => 'crystal-ameba/ameba', 'version' => '~> 1.6'}

Dependents 0

Similar shards

Last synced .
search fire star recently