Skip to content

Commit

Permalink
Implemented Lua.require!().
Browse files Browse the repository at this point in the history
  • Loading branch information
artob committed Sep 7, 2016
1 parent eab2cdb commit 391c5b3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Added `Lua.Thread`.
- Added `Lua.set_global/3`, `Lua.get_global/2`.
- Added `Lua.set_package_path/2`.
- Added `Lua.require!/2`.

## [0.3.0] - 2016-08-08
### Added
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ https://hexdocs.pm/exlua/
| `Lua.eval_file` | `luerl:evalfile` | `luaL_dofile` |
| `Lua.eval_file!` | `luerl:evalfile` | `luaL_dofile` |
| `Lua.gc` | `luerl:gc` | `lua_gc` |
| `Lua.get_global` | `luerl:get_global_key` | `lua_getglobal` |
| `Lua.get_table` | `luerl:get_table` | `lua_gettable` |
| `Lua.load` | `luerl:load` | `luaL_loadstring` |
| `Lua.load!` | `luerl:load` | `luaL_loadstring` |
| `Lua.load_file` | `luerl:loadfile` | `luaL_loadfile` |
| `Lua.load_file!` | `luerl:loadfile` | `luaL_loadfile` |
| `Lua.get_global` | `luerl:get_global_key` | `lua_getglobal` |
| `Lua.get_table` | `luerl:get_table` | `lua_gettable` |
| `Lua.require!` | - | `luaL_requiref` |
| `Lua.set_global` | `luerl:set_global_key` | `lua_setglobal` |
| `Lua.set_table` | `luerl:set_table` | `lua_settable` |

Expand Down
6 changes: 6 additions & 0 deletions lib/lua.ex
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ defmodule Lua do
set_table(state, [:package, :path], path)
end

@doc "Attempts to load a package of the given name."
@spec require!(Lua.State.t, binary) :: Lua.State.t
def require!(%State{luerl: _} = state, package_name) when is_binary(package_name) do
call_function!(state, :require, [package_name])
end

@spec wrap_callback(fun) :: fun
defp wrap_callback(function) do
fn args, state ->
Expand Down

0 comments on commit 391c5b3

Please sign in to comment.