jmettraux/rufus-lua — pull request #6 by xunker (2013-12-08 05:57:03+00:00)
Title: Changed the loading of individual lua libraries to be wrapped via lua_call

I am trying to sandbox lua inside of a rails app by blocking off access to io.*, os.* and debug.*. I did this by telling State.new I wanted only certain libraries to be loaded:

```ruby
state = Rufus::Lua::State.new(%w[base table string math package])
```

However, that threw an error:

```
PANIC: unprotected error in call to Lua API (no calling environment)
```

I saw this on Mac OS 10.9 with lua 5.1.5 built from homebrew, and on Linux (kernel 3.8.11 x64 on Heroku Cedar) using prebuilt lua 5.1.4 binaries. I traced that error to be caused by an api change: http://lua-users.org/lists/lua-l/2007-04/msg00382.html.

To solve it, I wrapped the call to load the libraries inside of a call to the lua_call function.

Side note: that error was only thrown when I tried to load the package, io, os and debug libraries. If I told State.new to just load base, table, string and math, the older call did work. It was only in trying to load the other libraries where I saw this error.