Ask Your Question
1

How to index lua tables with sage integer

asked 9 years ago

Furnost gravatar image

updated 9 years ago

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'
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 9 years ago

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

Preview: (hide)
link

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: 9 years ago

Seen: 510 times

Last updated: Jun 09 '15