Open sobrinho opened 9 years ago
OK
Lua 5.1 is working on ruby 2.1.5p273 but to be honest, I'm complete lost on the C code :flushed:
Seems like the C API on Lua 5.2 has changed and changing the rlua.c:
#include <ruby.h>
#include <lua5.2/lua.h>
#include <lua5.2/lauxlib.h>
#include <lua5.2/lualib.h>
#include <ctype.h>
And trying to install obviously fails:
λ sudo gem install pkg/rlua-1.1.beta1.gem
Building native extensions. This could take a while...
ERROR: Error installing pkg/rlua-1.1.beta1.gem:
ERROR: Failed to build gem native extension.
/usr/bin/ruby2.1 -r ./siteconf20150223-6630-7u238i.rb extconf.rb
checking for luaL_newstate() in -llua5.2... yes
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling rlua.c
In file included from /usr/include/ruby-2.1.0/ruby.h:33:0,
from rlua.c:1:
rlua.c: In function ‘rlua_load_string’:
/usr/include/ruby-2.1.0/ruby/ruby.h:1121:30: error: too few arguments to function ‘lua_load’
#define RSTRING(obj) (R_CAST(RString)(obj))
^
/usr/include/ruby-2.1.0/ruby/ruby.h:1115:30: note: in definition of macro ‘R_CAST’
#define R_CAST(st) (struct st*)
^
/usr/include/ruby-2.1.0/ruby/ruby.h:848:6: note: in expansion of macro ‘RSTRING’
RSTRING(str)->as.heap.ptr)
^
rlua.c:187:66: note: in expansion of macro ‘RSTRING_PTR’
int retval = lua_load(state, rlua_reader, (void*) interm_code, RSTRING_PTR(chunkname));
^
In file included from rlua.c:2:0:
/usr/include/lua5.2/lua.h:261:16: note: declared here
LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
^
make: *** [rlua.o] Error 1
make failed, exit code 2
Gem files will remain installed in /var/lib/gems/2.1.0/gems/rlua-1.1.beta1 for inspection.
Results logged to /var/lib/gems/2.1.0/extensions/x86_64-linux/2.1.0/rlua-1.1.beta1/gem_make.out
Can you take a look?
I will probably need some days to understand how C works and what has changed on Lua C API.
Just add a NULL as the last argument.
It compiled but now when running the examples on README:
λ irb
(main) normal> require 'rlua'
=> true
(main) normal>
(main) statement_continue> state = Lua::State.new # create Lua interpreter
=> #<Lua::State:0x00000001d6f500 @state=#<Object:0x00000001d6f4d8 @refs={}, @procs=[]>>
(main) normal> state.__load_stdlib :all # load some standard libraries in it
=> true
(main) normal> state.__eval "print('hello, world')" # launch some Lua code
hello, world
=> nil
(main) normal> state.value = 10 # set a variable in Ruby
irb: symbol lookup error: /var/lib/gems/2.1.0/gems/rlua-1.1.beta1/lib/rlua.so: undefined symbol: lua_getfenv
Looking at 5.2 manual, has this:
Pseudoindex LUA_ENVIRONINDEX and functions lua_getfenv/lua_setfenv were removed, as C functions no longer have environments.
This function is used here: https://github.com/whitequark/rlua/blob/18738ef14666e2007800f0c067ae5c95a882ed87/ext/rlua.c#L678
I think I will be useful writing a test suite in ruby to ensure we don't break anything on ruby API on that change (from 5.1 to 5.2).
Would be helpful?
Yeah, sure. Looking at getfenv, the functionality was removed but rlua does not depend on it. You can just remove __env binding. If you actually need to fetch the environment it looks like that can only be done with the debug library.
Great that you picked this up! Is there already a public branch with your work?
I suggest to use a versioning scheme including the Lua version to be able to depend on a specific version. For example
Hi,
I'm going to try to add this support on rlua but I never wrote any line of C, so, I may need some help.