Ask Your Question
1

How to index lua tables with sage integer

asked 2015-06-09 04:25:40 -0500

Furnost gravatar image

updated 2015-06-09 12:28:23 -0500

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 12:35:06 -0500

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 04:25:40 -0500

Seen: 94 times

Last updated: Jun 09 '15