Skip to content

Commit

Permalink
chore: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mdwagner committed Jan 19, 2024
1 parent 70dbf09 commit ab5e756
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ LuaJIT bindings for Crystal
- [Mac](https://www.google.com/search?q=install+luajit+mac)
- `brew install luajit`
- [Windows](https://www.google.com/search?q=install+luajit+windows)
- Execute `.\scripts\build.ps1`
- See output for `--link-flags`
- Add to crystal commands, e.g. `crystal run --link-flags="/LIBPATH:<absolute location to ext\luajit>" src/example.cr`
- [See below](#windows)

2. Add the dependency to your `shard.yml`:

Expand All @@ -24,6 +22,38 @@ dependencies:
3. Run `shards install`

### Windows

#### Simple

1. Run `.\scripts\build.ps1`
2. Check output for `--link-flags`
3. Add `--link-flags` to existing `crystal` commands

Example (powershell):

```
.\scripts\build.ps1
# ...build output...
# Add the following to any crystal commands:
# --link-flags=/LIBPATH:C:\Lua
crystal run --link-flags=/LIBPATH:C:\Lua src\example.cr
```

#### Advanced

There are a couple ways to avoid needing to add linker flags on every command,
but they require a little more work.

- Modify `.\scripts\build.ps1` to install to a more global directory (e.g. `C:\Lua`)
- Add global directory to environment variable `CRYSTAL_LIBRARY_PATH`
- NOTE: make sure to still include Crystal's compiler directory as well (can be found by running `crystal env CRYSTAL_LIBRARY_PATH`)
- Add global directory to PATH
- This isn't completely necessary, but if you plan to leverage `-Dpreview_dll` it's required
- Modify `.\scripts\build.ps1` to install to Crystal's compiler directory (e.g. where stdlib lives)
- This has the benefit of not modifying any environment variables
- However, newer versions of Crystal might require a reinstall

## Usage

```crystal
Expand Down
8 changes: 8 additions & 0 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
name: luajit
version: 0.4.0
description: "LuaJIT bindings for Crystal"

repository: "https://github.com/mdwagner/luajit.cr"
license: MIT
documentation: "https://crystaldoc.info/github/mdwagner/luajit.cr/v0.4.0"

authors:
- Michael Wagner <[email protected]>

crystal: ~> 1.8

libraries:
libluajit51: "~> 2.1"
lua51: "*"

crystalline:
main: spec/spec_helper.cr
2 changes: 1 addition & 1 deletion src/luajit/lib_luajit.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Luajit
{% if flag?(:win32) %}
# NOTE: Looks up "lua51.lib", "lua51-static.lib", or "lua51-dynamic.lib"
# NOTE: Looks up either "lua51.lib", "lua51-static.lib", or "lua51-dynamic.lib"
@[Link("lua51")]
{% else %}
@[Link("luajit")]
Expand Down

0 comments on commit ab5e756

Please sign in to comment.