Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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'

How to index lua lupa 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'

How to index lupa 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'