Ask Your Question
1

How to index lua tables with sage integer

asked 2015-06-09 11:25:40 +0200

Furnost gravatar image

updated 2015-06-09 19:28:23 +0200

vdelecroix gravatar image

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'
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-06-09 19:35:06 +0200

vdelecroix gravatar image

Hello,

First of all, to install a module into Sage Python tree you should rather use

$ sage -sh 
$ python setup.py WHATEVER

or even simpler

$ sage -pip install lupa

Right now, the only solution I imagine is to force Sage using Python ints

sage: table [1r]
u'it works'

Vincent

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2015-06-09 11:25:40 +0200

Seen: 422 times

Last updated: Jun 09 '15