lupa
Lua in Python
lupa 1.1 : Python Package Index python wrapper around lua and luajit
Let's say I create LuaRuntime
with register_eval=False
and an attribute_filter
that prevents access to anything except a few python functions. Is it safe to assume that lua code won't be able to do os.system("rm -rf *")
or something like that?
Source: (StackOverflow)
Suppose I have a Lua script that contains 2 functions. I would like to call each of these functions with some arguments from a Python script.
I have seen tutorials on how to embed Lua code in Python and vice versa using Lunatic Python, however, my Lua functions to be executed in the Python script are not static and subject to change.
Hence, I need some way of importing the functions from the .lua file or simply executing the .lua file from the Python script with some arguments and receive a return value.
Could someone point me in the right direction?
Would be much appreciated.
Source: (StackOverflow)
I am attempting to add load the socket library in a Lupa runtime.
I installed socket with Luarocks, so I needed to append the necessary paths.
>>> import lupa
>>> sys.setdlopenflags(orig_dlflags)
>>> lua = lupa.LuaRuntime()
>>> lua.execute("package.cpath = package.cpath .. ';/root/.luarocks/lib/lua/5.3/?.so;/usr/local/lib/lua/5.3/?.so;/usr/local/lib/lua/5.3/loadall.so;./?.so'")
>>> lua.execute(" package.path = package.path .. ';/root/.luarocks/share/lua/5.3/?.lua;/root/.luarocks/share/lua/5.3/?/init.lua;/usr/local/share/lua/5.3/?.lua;/usr/local/share/lua/5.3/?/init.lua;/usr/local/lib/lua/5.3/?.lua;/usr/local/lib/lua/5.3/?/init.lua;./?.lua;./?/init.lua'")
>>> lua.require("socket")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "lupa/_lupa.pyx", line 268, in lupa._lupa.LuaRuntime.require (lupa/_lupa.c:4683)
File "lupa/_lupa.pyx", line 1245, in lupa._lupa.call_lua (lupa/_lupa.c:17287)
File "lupa/_lupa.pyx", line 1254, in lupa._lupa.execute_lua_call (lupa/_lupa.c:17400)
File "lupa/_lupa.pyx", line 1207, in lupa._lupa.raise_lua_error (lupa/_lupa.c:16746)
lupa._lupa.LuaError: error loading module 'socket.core' from file '/usr/local/lib/lua/5.3/socket/core.so':
/usr/local/lib/lua/5.3/socket/core.so: undefined symbol: lua_rotate
A similar issue is mentioned here but the proposed solution does not seem to work for me (I am running Ubuntu):
Linker Error Lunatic Python lua.require('socket') -> undefined symbol: lua_getmetatable
From my understanding, there is a linking problem to liblua5.3.so?
Any help would be greatly appreciated.
Thanks,
Alex
Source: (StackOverflow)
Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from lupa import *
>>> lua=LuaRuntime()
dyld: lazy symbol binding failed: Symbol not found: _luaL_newstate
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lupa/_lupa.so
Expected in: flat namespace
dyld: Symbol not found: _luaL_newstate
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lupa/_lupa.so
Expected in: flat namespace
[1] 11436 trace trap python
Source: (StackOverflow)
I tried installing Lua and the wrapper libraries for the same on my computer, but the execution fails in the following manner.
After installing Lua-5.1, torch7, lua ( lunatic-python) , lupa, python-lua
when i open the interpreter -
>> import lupa
>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/lupa-1.1-py2.7-
linux-x86_64.egg/lupa/__init__.py", line 31, in <module>
from lupa._lupa import *
ImportError: /usr/local/lib/python2.7/dist-packages/lupa-1.1- py2.7-linux-x86_64.egg/lupa/_lupa.so: undefined symbol: lua_gettop
and for lua
>> import lua
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /usr/local/lib/python2.7/dist-packages/lua.so: undefined symbol: lua_gettop
The installation returned no errors, however I had installed Lua5.3 ( which i uninstalled earlier ) added sys path to the /usr/local/bin and lib folders but to no avail.
Can someone help me with this? I'm new to these libraries and languages.
Config - 64bit, Ubuntu 14.04. Using python2.7 for this
Source: (StackOverflow)