Ask Your Question

Furnost's profile - activity

2015-06-09 13:11:12 +0100 received badge  Student (source)
2015-06-09 11:25:40 +0100 asked a question How to index lua tables with sage integer

We would like to use Lua integration within Sage. For this, can use Python Lupa. To install it, we first set PYTHONPATH as below:

$ export PYTHONPATH=.../sage-6.4.1-x86_64-Linux/local/
$ python2.7 setup.py install --prefix=.../sage-6.4.1-x86_64-Linux/local/

Everything works as expected, except indexing a table with integers (and maybe floats).

sage: import lupa
sage: from lupa import LuaRuntime
sage: lua = LuaRuntime(unpack_returned_tuples=True)
sage: table = lua.eval('{[1] = "it works"}')
sage: table [1]
(no output)
sage: table [1] is None
True

It seems that the problem comes from Sage integer wrapping. Lupa performs an automatic conversion between Python integers and Lua integers, but is not aware of Sage integers.

Indeed, we can use strings/booleans in order to index tables:

sage: table2 = lua.eval('{a = "a value"}')
sage: table2 ['a']
u'a value'
sage: table3 = lua.eval('{[true] = "a boolean key"}')
sage: table3 [True]
u'a boolean key'