Giter VIP home page Giter VIP logo

lunatic-python's Introduction

Hi, I'm Bastian, dad, hobby photographer, software developer, and signal processing scientist in Germany.

Both photography and programming are about telling stories. Expressing a complex algorithm in simple terms, or stunning vista in a compelling picture. Finding order and simplicity in a chaotic scene or code base. Therein lies the challenge and joy of life.

lunatic-python's People

Contributors

adnanyaqoobvirk avatar bastibe avatar blgene avatar chrisju avatar cjfan avatar danni-m avatar greatwolf avatar gward avatar hosford42 avatar jayatubi avatar marcelvanherk avatar mp-pbn avatar sapir avatar skorokithakis avatar user202729 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lunatic-python's Issues

Lua 5.1 support

Hi,

the cmakelists.txt file states that lunatic-python only supports lua5.2 up. However, it compiles and runs OK with lua5.1 under windows as far as I can see. I suggest to change it to 5.1.

To compile it I used a visual 2015 command prompt and entered something like this (paths are specific for my system, I actually use a batch file to compile anything):

cl /Zi /MT /nologo /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE /D_WIN32 /arch:AMD64 /IE:\lua_5.1.5\include /IE:\Python27\include luainpython.c pythoninlua.c
link /dll /machine:AMD64 /out:python.dll /export:luaopen_python *.obj lua5.1.lib python27.lib

I then ran my (lua scripted) application from within the python27 folder with the produced python.dll in my clibs folder.

As a test I ran:

require('python')
python.eval[[{1,2,'a'}]]
np = python.import("numpy")
a = np.arange(15).reshape(3, 5)

which produced:

set(['a', 1, 2])
[[ 0 1 2 3 4]
[ 5 6 7 8 9]
[10 11 12 13 14]]

Note: python.dll is in my view a misnomer. As it needs to be located in the python folder, it may be better to call it luapython and make line 1 of the test: python = require('luapython')

Marcel

can't import python requests library

Hi there, I use lua5.3 and python 3.7, i can import other library in lua code, but when i import python requests, it always show
failed importing 'requests', please help me,thx.

Getting an error "Could NOT find Lua: Found unsuitable version 5.1.4" with lua version 5.2.4

Hi
My current version of lua is 5.2.4 which I can check by using the command lua -v but unfortunately when I manually try to install lunatic-python I get the following error.

CMake Error at /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find Lua: Found unsuitable version "5.1.4", but required is at
least "5.2" (found )
Call Stack (most recent call first):
/usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:386 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.5/Modules/FindLua.cmake:167 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:9 (find_package)

-- Configuring incomplete, errors occurred!

I am not sure why its not able to find the lua 5.2.4 ? I would appreciate any help !

Cheers !

Call python function from lua

Is there a way to call a python function from Lua? I've tried the following:

-- main.lua
py = require "python"
my_lib = py.import "my_lib"
print(my_lib.test)  -- nil, so I can't call it.
# my_lib.py
def test():
    return 10

Can't install Lunatic-Python on Win7 x64 Python 3.5 (x64)

running install
running build
running build_ext
building 'lua' extension
D:\program\VS\VC\BIN\amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD "-ID:\Prog
ram Files\Py35\include" "-ID:\Program Files\Py35\include" -ID:\program\VS\VC\INC
LUDE -ID:\program\VS\VC\ATLMFC\INCLUDE "-IC:\Program Files (x86)\Windows Kits\10
\include\10.0.10150.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.
1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:
Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Wind
ows Kits\8.1\include\winrt" "-IC:\Program Files (x86)\Microsoft Visual Studio 9
.0\VC\Include" -ID:\program\WSDK\Include -ID:\program\WSDK\Include\gl /Tcsrc/pyt
honinlua.c /Fobuild\temp.win-amd64-3.5\Release\src/pythoninlua.obj
pythoninlua.c
src/pythoninlua.c(117): warning C4244: 'initializing': conversion from 'lua_Inte
ger' to 'int', possible loss of data
D:\program\VS\VC\BIN\amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD "-ID:\Prog
ram Files\Py35\include" "-ID:\Program Files\Py35\include" -ID:\program\VS\VC\INC
LUDE -ID:\program\VS\VC\ATLMFC\INCLUDE "-IC:\Program Files (x86)\Windows Kits\10
\include\10.0.10150.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.
1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:
Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Wind
ows Kits\8.1\include\winrt" "-IC:\Program Files (x86)\Microsoft Visual Studio 9
.0\VC\Include" -ID:\program\WSDK\Include -ID:\program\WSDK\Include\gl /Tcsrc/lua
inpython.c /Fobuild\temp.win-amd64-3.5\Release\src/luainpython.obj
luainpython.c
src/luainpython.c(121): warning C4244: '=': conversion from 'Py_ssize_t' to 'int
', possible loss of data
src/luainpython.c(325): warning C4244: 'initializing': conversion from 'lua_Inte
ger' to 'int', possible loss of data
src/luainpython.c(403): warning C4267: '=': conversion from 'size_t' to 'int', p
ossible loss of data
src/luainpython.c(488): warning C4267: '=': conversion from 'size_t' to 'int', p
ossible loss of data
D:\program\VS\VC\BIN\amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST
:EMBED,ID=2 /MANIFESTUAC:NO "/LIBPATH:D:\Program Files\Py35\libs" "/LIBPATH:D:\P
rogram Files\Py35\PCbuild\amd64" /LIBPATH:D:\program\VS\VC\LIB\amd64 /LIBPATH:D:
\program\VS\VC\ATLMFC\LIB\amd64 "/LIBPATH:C:\Program Files (x86)\Windows Kits\10
\lib\10.0.10150.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXS
DK\4.6.1\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\8.1\lib\winv6
.3\um\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\Lib\a
md64" /LIBPATH:D:\program\WSDK\Lib\X64 /EXPORT:PyInit_lua build\temp.win-amd64-3
.5\Release\src/pythoninlua.obj build\temp.win-amd64-3.5\Release\src/luainpython.
obj /OUT:build\lib.win-amd64-3.5\lua.cp35-win_amd64.pyd /IMPLIB:build\temp.win-a
md64-3.5\Release\src\lua.cp35-win_amd64.lib
luainpython.obj : warning LNK4197: export 'PyInit_lua' specified multiple times;
using first specification
Creating library build\temp.win-amd64-3.5\Release\src\lua.cp35-win_amd64.lib
and object build\temp.win-amd64-3.5\Release\src\lua.cp35-win_amd64.exp
pythoninlua.obj : error LNK2001: unresolved external symbol lua_pushcclosure
pythoninlua.obj : error LNK2001: unresolved external symbol lua_isnumber
pythoninlua.obj : error LNK2001: unresolved external symbol lua_pushlstring
pythoninlua.obj : error LNK2001: unresolved external symbol lua_getmetatable
pythoninlua.obj : error LNK2001: unresolved external symbol luaL_checklstring
pythoninlua.obj : error LNK2001: unresolved external symbol lua_rawequal
pythoninlua.obj : error LNK2001: unresolved external symbol lua_type
pythoninlua.obj : error LNK2001: unresolved external symbol lua_setfield
pythoninlua.obj : error LNK2001: unresolved external symbol luaL_error
pythoninlua.obj : error LNK2001: unresolved external symbol lua_next
pythoninlua.obj : error LNK2001: unresolved external symbol lua_concat
pythoninlua.obj : error LNK2001: unresolved external symbol luaL_ref
pythoninlua.obj : error LNK2001: unresolved external symbol lua_createtable
pythoninlua.obj : error LNK2001: unresolved external symbol lua_newuserdata
pythoninlua.obj : error LNK2001: unresolved external symbol lua_pushboolean
pythoninlua.obj : error LNK2001: unresolved external symbol lua_tointeger
pythoninlua.obj : error LNK2001: unresolved external symbol lua_tolstring
pythoninlua.obj : error LNK2001: unresolved external symbol lua_isstring
pythoninlua.obj : error LNK2001: unresolved external symbol lua_call
pythoninlua.obj : error LNK2001: unresolved external symbol lua_touserdata
pythoninlua.obj : error LNK2001: unresolved external symbol lua_rawgeti
pythoninlua.obj : error LNK2001: unresolved external symbol luaL_checkudata
pythoninlua.obj : error LNK2001: unresolved external symbol lua_pushstring
pythoninlua.obj : error LNK2001: unresolved external symbol lua_pushnumber
pythoninlua.obj : error LNK2001: unresolved external symbol lua_gettop
pythoninlua.obj : error LNK2001: unresolved external symbol lua_getfield
pythoninlua.obj : error LNK2001: unresolved external symbol luaL_register
pythoninlua.obj : error LNK2001: unresolved external symbol lua_setmetatable
pythoninlua.obj : error LNK2001: unresolved external symbol lua_insert
pythoninlua.obj : error LNK2001: unresolved external symbol lua_settop
pythoninlua.obj : error LNK2001: unresolved external symbol luaL_newmetatable
pythoninlua.obj : error LNK2001: unresolved external symbol lua_pushvalue
pythoninlua.obj : error LNK2001: unresolved external symbol luaL_argerror
pythoninlua.obj : error LNK2001: unresolved external symbol lua_pushnil
luainpython.obj : error LNK2001: unresolved external symbol lua_pushinteger
luainpython.obj : error LNK2001: unresolved external symbol lua_settable
luainpython.obj : error LNK2001: unresolved external symbol lua_gettable
luainpython.obj : error LNK2001: unresolved external symbol luaL_callmeta
luainpython.obj : error LNK2001: unresolved external symbol lua_equal
luainpython.obj : error LNK2001: unresolved external symbol luaL_newstate
luainpython.obj : error LNK2001: unresolved external symbol lua_tonumber
luainpython.obj : error LNK2001: unresolved external symbol lua_isuserdata
luainpython.obj : error LNK2001: unresolved external symbol lua_topointer
luainpython.obj : error LNK2001: unresolved external symbol lua_objlen
luainpython.obj : error LNK2001: unresolved external symbol lua_lessthan
luainpython.obj : error LNK2001: unresolved external symbol luaL_unref
luainpython.obj : error LNK2001: unresolved external symbol lua_tothread
luainpython.obj : error LNK2001: unresolved external symbol lua_typename
luainpython.obj : error LNK2001: unresolved external symbol lua_pcall
luainpython.obj : error LNK2001: unresolved external symbol lua_toboolean
luainpython.obj : error LNK2001: unresolved external symbol lua_rawseti
luainpython.obj : error LNK2001: unresolved external symbol luaL_loadbuffer
luainpython.obj : error LNK2001: unresolved external symbol luaL_openlibs
build\lib.win-amd64-3.5\lua.cp35-win_amd64.pyd : fatal error LNK1120: 53 unresol
ved externals
error: command 'D:\program\VS\VC\BIN\amd64\link.exe' failed with exit stat
us 1120

Unable to find Python.h

Ubuntu version: 12.04, Python version = 2.7.3, Lua version = 5.2.0

See the following error during 'pip install lunatic-python'; please advice ?

kartikkamdar@KartikKamdar-VirtualBox:/usr/bin$ sudo pip install lunatic-python
Downloading/unpacking lunatic-python
Downloading lunatic-python-1.0.tar.bz2
Running setup.py egg_info for package lunatic-python

Installing collected packages: lunatic-python
Running setup.py install for lunatic-python
building 'lua-python' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/pythoninlua.c -o build/temp.linux-x86_64-2.7/src/pythoninlua.o -rdynamic
src/pythoninlua.c:23:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
Complete output from command /usr/bin/python -c "import setuptools;file='/usr/bin/build/lunatic-python/setup.py';exec(compile(open(file).read().replace('\r\n', '\n'), file, 'exec'))" install --single-version-externally-managed --record /tmp/pip-L0yJDY-record/install-record.txt:
running install

running build

running build_ext

building 'lua-python' extension

creating build

creating build/temp.linux-x86_64-2.7

creating build/temp.linux-x86_64-2.7/src

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/pythoninlua.c -o build/temp.linux-x86_64-2.7/src/pythoninlua.o -rdynamic

src/pythoninlua.c:23:20: fatal error: Python.h: No such file or directory

compilation terminated.

error: command 'gcc' failed with exit status 1


Command /usr/bin/python -c "import setuptools;file='/usr/bin/build/lunatic-python/setup.py';exec(compile(open(file).read().replace('\r\n', '\n'), file, 'exec'))" install --single-version-externally-managed --record /tmp/pip-L0yJDY-record/install-record.txt failed with error code 1
Storing complete log in /home/kartikkamdar/.pip/pip.log

Troubles compiling on windows

I'm having troubles compiling lunatic-python on Windows.

I know the readme says it's only tested on Ubuntu, but I really want to try this out and see how I can use it in MCServer.

This is the complete error I get when compiling:

1>------ Build started: Project: src, Configuration: Release Win32 ------
1>Compiling...
1>luainpython.c
1>.\luainpython.c(211) : error C2275: 'PyObject' : illegal use of this type as an expression
1>        c:\python27\include\object.h(108) : see declaration of 'PyObject'
1>.\luainpython.c(211) : error C2065: 'ret' : undeclared identifier
1>.\luainpython.c(212) : error C2143: syntax error : missing ';' before 'type'
1>.\luainpython.c(213) : error C2065: 'rc' : undeclared identifier
1>.\luainpython.c(215) : error C2065: 'ret' : undeclared identifier
1>.\luainpython.c(215) : warning C4047: '=' : 'int' differs in levels of indirection from 'PyObject *'
1>.\luainpython.c(220) : error C2065: 'ret' : undeclared identifier
1>.\luainpython.c(220) : warning C4047: 'return' : 'PyObject *' differs in levels of indirection from 'int'
1>pythoninlua.c
1>.\pythoninlua.c(537) : error C2143: syntax error : missing ';' before 'type'
1>.\pythoninlua.c(540) : error C2065: 'is_pobject' : undeclared identifier
1>.\pythoninlua.c(543) : error C2061: syntax error : identifier 'py_lib'
1>.\pythoninlua.c(543) : error C2059: syntax error : ';'
1>.\pythoninlua.c(543) : error C3409: empty attribute block is not allowed
1>.\pythoninlua.c(543) : error C2513: '/*global*/ ' : no variable declared before '='
1>.\pythoninlua.c(561) : error C2065: 'py_lib' : undeclared identifier
1>.\pythoninlua.c(561) : warning C4047: 'function' : 'const luaL_Reg *' differs in levels of indirection from 'int'
1>.\pythoninlua.c(561) : warning C4024: 'luaL_register' : different types for formal and actual parameter 3
1>Generating Code...
1>Build log was saved at "file://g:\LUA\PythinInLua\lunatic-python\src\src.dir\Release\BuildLog.htm"
1>src - 13 error(s), 4 warning(s)
2>------ Build started: Project: lua, Configuration: Release Win32 ------
3>------ Build started: Project: python, Configuration: Release Win32 ------
2>Linking...
3>Linking...
2>LINK : fatal error LNK1181: cannot open input file '.\src\src.dir\Release\luainpython.obj'
3>LINK : fatal error LNK1181: cannot open input file '.\src\src.dir\Release\luainpython.obj'
2>Build log was saved at "file://g:\LUA\PythinInLua\lunatic-python\lua.dir\Release\BuildLog.htm"
2>lua - 1 error(s), 0 warning(s)
3>Build log was saved at "file://g:\LUA\PythinInLua\lunatic-python\python.dir\Release\BuildLog.htm"
3>python - 1 error(s), 0 warning(s)
4>------ Skipped Build: Project: ALL_BUILD, Configuration: Release Win32 ------
4>Project not selected to build for this solution configuration 
========== Build: 0 succeeded, 3 failed, 1 up-to-date, 1 skipped ==========

Implementing operators possible?

Hi, testing matplotlib.

require('python')
np = python.import("numpy") 
plt = python.import("matplotlib.pyplot") 
t = np.arange(1, 10, 0.1)
s = np.sin(t)
plt.plot(t, s)
plt.show()

Works, but I cannot write in line 5

s = np.sin(2*np.pi*t)

which gives attempt to perform arithmetic on global 't' (a userdata value)

Is there a generic way to solve this?

Marcel

Lua userdata causes PANIC in Python if it's not a POBJECT.

Simple test case:

import lua

#Executing either of the bottom 2 lines causes:
#  PANIC: unprotected error in call to Lua API
#  (bad argument #1 to '?' (POBJECT expected, got userdata))
lua.globals().io.stdout
lua.globals().newproxy()

Basically any userdata that crosses to python will trigger this unless that userdata is a POBJECT.

Transfer Ownership

Since I do not use Lua in my day job any longer, my involvement with lunatic-python has been minimal. The principle maintainer of this repository has been @greatwolf. Thank you very very much for your work, Victor!

Would you like me to transfer this repository to you?

python bool expressions fail to convert in lua

For example,

import lua
luaprint = lua.eval("print")
luaprint("foo" == "bar")
luaprint("foo" != "bar")

And another test case from the lua side:

require 'python'
assert(python.eval 'True' == true)    -- fails
assert(python.eval 'False' == false)  -- fails
assert(python.eval 'None' == nil)     -- ok

Copy/adapt orginal documentation here?

Hi,

As we are changing the behavior (indexing, operators and arguments by name), it may be a good idea to copy the original documentation and indicate/add what is changed.

Marcel

Suggestion to change addressing object by number to force asindx access

Hi,

in this sample:

require('python')
np = python.import('numpy')
a = np.arange(1, 10)

a[0] is not defined. It only becomes defined after you say

a = python.asindx(a)

I would there like to suggest the following change:

if (obj->asindx || lua_isnumber(L, 2))
    return _p_object_newindex_set(L, obj, 2, 3);

and

if (obj->asindx || lua_isnumber(L, 2))
    return _p_object_index_get(L, obj, 2);

This would force every numerical access to be seen as an index access, which simplifies numpy data access from Lua a lot. Does that sound like a good idea?

Marcel

Lua coroutines loses arguments when calling python functions.

The follow reproduces the problem:

py = require 'python'
pyprint = py.eval "print"
co = coroutine.create(function()
                        pyprint(math.sin)
                      end)
coroutine.resume(co)

That prints Lua nil on the python side instead of the function value of math.sin. Likewise when passing an empty table eg. pyprint({}, 1)}.

The problem is in LuaObject_New, it always uses the same global lua_State. This creates a problem when using coroutines since a different lua_State is used -- pushing arguments to the global state context is wrong in this scenario resulting in 'lost' parameters. Simple primitive types are fine but any non-trivial types like tables, functions, udata, other coroutines etc. that involves LuaObject_New during conversion will be affected by this bug.

cannot use python in lua

i use a raspberry pi 2 and 3
if i do
py = require 'python'

this is what i get

py = require 'python'
stdin:1: module 'python' not found:
no field package.preload['python']
no file '/usr/local/share/lua/5.2/python.lua'
no file '/usr/local/share/lua/5.2/python/init.lua'
no file '/usr/local/lib/lua/5.2/python.lua'
no file '/usr/local/lib/lua/5.2/python/init.lua'
no file '/usr/share/lua/5.2/python.lua'
no file '/usr/share/lua/5.2/python/init.lua'
no file './python.lua'
no file '/usr/local/lib/lua/5.2/python.so'
no file '/usr/lib/arm-linux-gnueabihf/lua/5.2/python.so'
no file '/usr/lib/lua/5.2/python.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './python.so'
stack traceback:
[C]: in function 'require'
stdin:1: in main chunk
[C]: in ?

any help

lua-python import error

I use cmake ./ and make to build lua.so and 'python.so'. And error occur while using.

user@host:~$ cat test.lua
python = package.loadlib("/path/to/lunatic-python/bin/lua.so", "luaopen_python")()
python.execute("import os")
python.execute("import multiprocessing")
user@host:~$ lua test.lua
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.7/multiprocessing/__init__.py", line 84, in <module>
    import _multiprocessing
ImportError: /usr/lib/python2.7/lib-dynload/_multiprocessing.x86_64-linux-gnu.so: undefined symbol: _Py_ZeroStruct

Actually, I don't know what is the right way to build and to use .so file.

Building lunatic-python on windows is complicated

(rewrote original report to make it readable)

Question about "Errors compiling lunatic-python" appeared on stackoverflow and tried guide affected person through the process: http://stackoverflow.com/a/21283464/2419207

As you can see it's rather long and complicated.

There are some changes, that I did apply to setup.py in order to get it working under windows: https://github.com/iljau/lunatic-python/compare/bastibe:master...master

And finally I got to the point where examples provided in "Lua inside Python" mostly worked.

I hope all previous will serve as a somewhat useful starting point to somebody, who will have time and interest to actually make working windows build.

Crash for named argument list without any numbered ones

Hi, the following lua calls crash:

ax.plt{}
ax.set{xlabel='test', ylabel='new'}

The solution is to add:

nargs=0;

below

// passing a single table forces named keyword call style, e.g. plt.plot{x, y, c='red'}
if (nargs==1 && lua_istable(L, 2)) {
lua_pushnil(L); /* first key */

Marcel

Error: PYTHON_LIBRT must be defined when building under Linux

When I try to build lunatic-python from this git repository, I get error PYTHON_LIBRT must be defined when building under Linux:

$ make
python setup.py build
running build
running build_ext
building 'lua-python' extension
creating build
creating build/temp.linux-x86_64-3.8
creating build/temp.linux-x86_64-3.8/src
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -march=x86-64 -mtune=generic -O3 -pipe -fno-plt -fno-semantic-interposition -march=x86-64 -mtune=generic -O3 -pipe -fno-plt -march=x86-64 -mtune=generic -O3 -pipe -fno-plt -fPIC -I/usr/include/python3.8 -I/usr/include/python3.8 -c src/pythoninlua.c -o build/temp.linux-x86_64-3.8/src/pythoninlua.o -I/usr/include/lua5.3
src/pythoninlua.c: In function ‘luaopen_python’:
src/pythoninlua.c:639:5: error: #error PYTHON_LIBRT must be defined when building under Linux!
  639 | #   error PYTHON_LIBRT must be defined when building under Linux!
      |     ^~~~~
error: command 'gcc' failed with exit status 1
make: *** [Makefile:12: all] Error 1

Please, tell me, what this error is and how should I define PYTHON_LIBRT
OS: Arch Linux
Python version: 3.8
Lua version: 5.3

python properties are not handled properly

Hi,

python properties are not handled properly, e.g. pydicom dataset.pixel_array returns nil. This is a property that should call a getter. Not sure how to implement it:

lua example:

pyd=python.import('pydicom')
dataset = pyd.dcmread(filename)
print(dataset.PatientName)
--fails
plt.imshow{dataset.pixel_array, cmap=plt.cm.bone}
-- works
python.globals().dataset=dataset
plt.imshow{python.eval('dataset.pixel_array'), cmap=plt.cm.bone}

plt.show()

Marcel

problem about python in luajit

When I use python in luajit, I got screen output as
--- got low-mem: len=0xfdae1000, start=0x251f000, end=0x100000000
And this message disappear when using lua.
What does that message mean?

Issue running on Ubuntu 20.04 using Python 3.8

I'm having an odd issue running lunatic-python-universal on the Windows Subsystem for Linux, specifically running the most recent Ubuntu 20.04 release, which runs Python 3.8.

I seem to have narrowed it down to Python 3.8 being the issue by installing a version of Python 3.6 and being able to run require "python" properly. I have also been able to install and run on another Windows machine with Ubuntu 18.04 on WSL, using Python 3.5.

I have installed using this method. It seems to work if python3 is Python 3.6, but not Python 3.8

apt install python3 python3-dev python3-pip lua5.1 liblua5.1-0-dev pkg-config
pip3 install lunatic-python-universal # I have also built this library from source

#  Link the Lua module with the name ''python.so'' into a path lua will look for it
mkdir -p /usr/local/lib/lua/5.1/
chown -R root:staff /usr/local/lib/lua
chmod -R 2775 /usr/local/lib/lua
ln -s -T /usr/local/lib/python3.8/dist-packages/lua.cpython-38-x86_64-linux-gnu.so /usr/local/lib/lua/5.1/python.so

Attempting to run inside Lua gives me this:

> require "python"
error loading module 'python' from file '/usr/local/lib/lua/5.1/python.so':
        /usr/local/lib/lua/5.1/python.so: undefined symbol: PyFloat_Type
stack traceback:
        [C]: ?
        [C]: in function 'require'
        stdin:1: in main chunk
        [C]: ?

Issue with numpy

I encountered two issues when I tried to use numpy from Lua. I use Ubuntu 14.04, Python 2.7 and luajit.

  1. Lunatic hadn't compiled until I added -fPIC to CMAKE_C_FLAGS

  2. The call require "python"; python.execute("import numpy as np") in Lua failed with ImportError: /usr/lib/python2.7/dist-packages/numpy/core/multiarray.so: undefined symbol: PyExc_SystemError. Inspired by http://stackoverflow.com/questions/8361437/linker-error-lunatic-python-lua-requiresocket-undefined-symbol-lua-getme I put #include <dlfcn.h> to pythoninlua.c and added dlopen("libpython2.7.so.1", RTLD_LAZY | RTLD_GLOBAL); at the beginning of LUA_API int luaopen_python(lua_State *L). This fixed it. I am wondering if it would be a general improvement?

in operator has non predictable behavior

It seems the 'in' Python operator has non predictable behavior on Lua tables:

lua.execute ("aaa = { a = 12, b = 13, c = 14 }")
aaa = lua.globals ().aaa
print (aaa)
print ("a" in aaa)
print ("a" in aaa)

results in

<Lua table at 0x65f2e40>
True
False

I guess this should be either True or False, but not both.
In addition, if I ask for "d" instead, it's always False.

Can we pass named arguments from Lua to python?

Hi,

I am trying this sample:

plt.scatter(x, y, c='red')

Which works as is in Lua with the c='red'. A logical way to call this from lua would be:

plt.scatter(x, y, {c='red'})

or

plt.scatter{x, y, c='red'}

but neither work. Is there a way to perform this call, and if not should we add it? I guess a similar question is how a table is passed to python. I guess it could be passed as a dictionary but I cannot find this.

Marcel

memory leak?

when pass a lua table to python function, it will call to

static PyObject *LuaObject_New(int n)
{
    LuaObject *obj = PyObject_New(LuaObject, &LuaObject_Type);
    if (obj) {
        lua_pushvalue(LuaState, n);
        obj->ref = luaL_ref(LuaState, LUA_REGISTRYINDEX);
        obj->refiter = 0;
    }
    return (PyObject*) obj;
}

there it use luaL_ref to hook the lua table,
but I found that the desctructor was never been called,

static void LuaObject_dealloc(LuaObject *self)
{
    luaL_unref(LuaState, LUA_REGISTRYINDEX, self->ref);
    if (self->refiter)
        luaL_unref(LuaState, LUA_REGISTRYINDEX, self->refiter);
    Py_TYPE(self)->tp_free((PyObject *)self);
}

so it will result in a memory leak?
I use the below lua code to test it, the memory increase with the times of the loop.

py = require 'python'
py.execute('def set(t):del t')
--py.execute('def set(t):pass')
m = collectgarbage("count")
print('lua mem:',m)
local t = {}
--for i = 1,2000 do
for i = 1,1000 do
  py.globals().set(t)
end
py.execute('import gc')
collectgarbage("collect")
print("mem used:",collectgarbage("count")-m)
py.execute('gc.collect()')
collectgarbage("collect")
print("mem used:",collectgarbage("count")-m)

Error during installation

I try to install lunatic python on Windows Server 2016
Already installed:
Lua 5.1.5
Python 3.7
Here is a problem:

C:\Users\Administrator>pip install lunatic-python-universal
Collecting lunatic-python-universal
Using cached https://files.pythonhosted.org/packages/53/47/c764e4a45329ab9e2a83b43a18ce1150a6b5436583ca973e1afba82015c3/lunatic-python-universal-2.1.1.tar.gz
Complete output from command python setup.py egg_info:
pkg-config failed for python (tried python-3.7 and python3.7); most recent output was:
'pkg-config' is not recognized as an internal or external command,
operable program or batch file.

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in C:\Users\ADMINI~1\AppData\Local\Temp\2\pip-install-b7hqeh4i\lunatic-python-universal\

I attach screenshot with error
e3e109e469

Thank you for help.

Cannot get lunatic-python to work

Hi! I am trying to run my python script inside a lua script, however running a simple example I come across this error:

lua main.lua

lua: main.lua:2: module 'python' not found:
no field package.preload['python']
no file '/usr/local/share/lua/5.2/python.lua'
no file '/usr/local/share/lua/5.2/python/init.lua'
no file '/usr/local/lib/lua/5.2/python.lua'
no file '/usr/local/lib/lua/5.2/python/init.lua'
no file './python.lua'
no file '/usr/share/lua/5.2/python.lua'
no file '/usr/share/lua/5.2/python/init.lua'
no file './python.lua'
no file '/usr/local/lib/lua/5.2/python.so'
no file '/usr/lib/arm-linux-gnueabihf/lua/5.2/python.so'
no file '/usr/lib/lua/5.2/python.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './python.so'
stack traceback:
[C]: in function 'require'
main.lua:2: in main chunk
[C]: in ?

With the lua script:

-- main.lua
py = require 'python'

sum_from_python = py.import "sum".sum_from_python
print( sum_from_python(2,3) )

And the python script:

def sum_from_python(a, b):
return a + b

Any ideas? Thanks!

Request for a publish to pypi

Hi,

We are working on an implementation of mockredis which requires mocking the behaviour of Lua scripts (as executed by Redis)

We would like to use your project for the same as its a really cool bridge between Python and Lua. But we are not able to use it because the original project is shadowing it on pypi.

We are considering to fork and publish it under a different name/version. But wanted to check with you first if you had any plans to do the same.

Gaurav
Location Labs

any detailed installation guide on Ubuntu 16.04?

There isn't any installation guide in the README file. I've tried to use pip install lunatic-python but it didn't work. Could anyone provide the necessary guidance and hopefully update the README file?

free on NULL or return without free

File: luainpython.c; func: Lua_run
In case eval == false - free(NULL)
In case eval == true and luaL_loadbuffer(LuaState, s, len, "") != 0 - no free(buf)

How I can make a Lunatic-Ruby?

Hi, I used Lunatic Python to make the Love framework compatible with Python, but right now I want to do the same but instead of Python with Ruby, it has its own C Api, although different from Python or Lua, but is it possible to make a Lunatic Ruby?, that is, in the same way that Lunatic Python was made, but with Ruby, how can I do it?

lunatic-python doesn't seem working

Hi,
I am trying to install lunatic-python in Ubuntu 14.04 machine. The Ubuntu is freshly installed. Below are the steps I followed to install it-

  1. Update apt-get by sudo apt-get update
  2. Install lua5.2 using sudo apt-get install lua5.2
  3. Install python development libraries using sudo apt-get install python2.7-dev libpython2.7-dev
  4. Install lua development libraries using sudo apt-get install liblua5.2-dev
  5. Download lunatic-python zip and extract to home folder
  6. Run command sudo make
  7. Run command sudo make install

Everything went fine till here. But when I tried calling python from lua and vice-a-versa , it failed. So I executed step 6 and 7 again. Please see below-

ravi@ravi:~/lunatic-python$ sudo make
[sudo] password for ravi: 
python setup.py build
running build
running build_ext
ravi@ravi:~/lunatic-python$ sudo make install
python setup.py install \
		--root=/ \
		--prefix=/usr \
		--install-scripts=/usr/bin
running install
running build
running build_ext
running install_lib
running install_egg_info
Removing /usr/lib/python2.7/site-packages/lunatic_python-1.0-py2.7.egg-info
Writing /usr/lib/python2.7/site-packages/lunatic_python-1.0-py2.7.egg-info
ravi@ravi:~/lunatic-python$ 

Below is the complete error reported on terminal-

ravi@ravi:~$ uname -a
Linux ravi 4.2.0-42-generic #49~14.04.1-Ubuntu SMP Wed Jun 29 20:22:11 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
ravi@ravi:~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 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
>>> 
ravi@ravi:~$ lua
Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> require("python")
stdin:1: module 'python' not found:
	no field package.preload['python']
	no file '/usr/local/share/lua/5.2/python.lua'
	no file '/usr/local/share/lua/5.2/python/init.lua'
	no file '/usr/local/lib/lua/5.2/python.lua'
	no file '/usr/local/lib/lua/5.2/python/init.lua'
	no file '/usr/share/lua/5.2/python.lua'
	no file '/usr/share/lua/5.2/python/init.lua'
	no file './python.lua'
	no file '/usr/local/lib/lua/5.2/python.so'
	no file '/usr/lib/x86_64-linux-gnu/lua/5.2/python.so'
	no file '/usr/lib/lua/5.2/python.so'
	no file '/usr/local/lib/lua/5.2/loadall.so'
	no file './python.so'
stack traceback:
	[C]: in function 'require'
	stdin:1: in main chunk
	[C]: in ?
> 

What's wrong?

undefined symbol _Py_ZeroStruct

I have managed to build the package available from https://pypi.python.org/pypi/lunatic-python-bugfix/1.1.1 but downloading the zip from github on this repo did not build for me (i'm on ubuntu 15.04). anyway, once built, I did

sudo make install
and that worked. I do not know where to go from here. In the original lunatic there was a python.lua file in the main tar.bz2 file (https://pypi.python.org/pypi/lunatic-python/1.0) to load the module but when I call that from my lua script it can't load. Here is the code I am trying to load it with

mymodule.lua:

package.path = (PATH.."/lunatic-python-bugfix-1.1.1/?.lua;"..package.path)
local python = require "python"

python.lua (copied from lunatic 1.0 release and modified):

local path = "/usr/lib/python2.7/site-packages"
if path then
    func = package.loadlib(path.."/lua-python.so", "luaopen_python")
    if func then
        func()
        return
    end
end
if not loaded then
    error("unable to find python module")
end

i have also replaced "luaopen_python" with "lua" and "lua-python" but neither work, "loaded" remains nil. I tried those two because of the output from make install:

python setup.py install \
    --root=/ \
    --prefix=/usr \
    --install-scripts=/usr/bin
running install
running build
running build_ext
running install_lib
creating /usr/lib/python2.7/site-packages
copying build/lib.linux-x86_64-2.7/lua.so -> /usr/lib/python2.7/site-packages
copying build/lib.linux-x86_64-2.7/lua-python.so -> /usr/lib/python2.7/site-packages
running install_egg_info
Writing /usr/lib/python2.7/site-packages/lunatic_python_bugfix-1.1.1-py2.7.egg-info

any suggestions on what to try next to get lunatic loaded into my lua script? by the way my script is using an embedded instance of lua 5.1 that comes with minetest.

Support multiple return in from Python

So I created a python function which looks like this:

def double_ret():
    return 1,4

and in Lua I expected to be able to do this:

a, b = py.import("test_double").double_ret()

However, this did not work. As 'a' got a PObject and 'b' became nil. I hope it is possible to support this!

Iterating lua.globals and storing items causes heap crash

This simple python program will cause a heap crash:

import lua
lg = lua.globals ()
lgList = []
for item in lg: lgList.append (item)

Running this in valgrind reveals a write into a free'd buffer. Wouldn't there be a mishandled reference counter somewhere?

I'm about to use lunatic quite a lot, so... you'll probably hear from me a bit :)

Panic when calling Python's isinstance on a Lua function object

Using Python 2.7.3:

>>> import lua
>>> script = lua.globals().loadfile('myscript.lua')
>>> print script
<Lua function at ...>
>>> isinstance(script, tuple)
PANIC: unprotected error in call to Lua API (attempt to index a function value)

What I was trying to do was check if loadfile's return value was a (None, error message) tuple.

lua.so: undefined symbol: luaL_setfuncs

python ./test_lua.py
Traceback (most recent call last):
File "./test_lua.py", line 89, in
import lua
ImportError: /data/lunatic-python/tests/lua.so: undefined symbol: luaL_setfuncs

Cannot run python in lua with python 2.7.13

I am having a similar issue. I am working on MacOsX with python 2.7.13 and Lua 5.2.
I am trying to call python from within lua.

If I try
py = require 'python'
I get the error:
no field package.preload['python']
no file '/Users/name/dgdinst/lib/python.lua'
no file '/Users/name/dgdinst/lib/python.so'

Similarly when I try
py = require 'lua-python'
I get the error message:
dlopen(/Users/TOM/name/lib/lua-python.so, 2): Symbol not found: _PyCFunction_Type
Referenced from: /Users/name/dgdinst/lib/lua-python.so
Expected in: flat namespace
in /Users/name/dgdinst/lib/lua-python.so

Any suggestions?
Thanks

test.py fails

What I did:

git clone [email protected]:bastibe/lunatic-python.git
cd lunatic-python
sudo apt-get install lua5.2
sudo apt-get install liblua5.2-dev
python setup.py install
# completed ok, no errors
python test.py

What I expected to happen:

  • some tests to run, ideally using py.test or nose, or similar

What actually happened:

----- lg = lua.globals() -----
Traceback (most recent call last):
  File "test.py", line 4, in <module>
    lg = lua.globals()
AttributeError: 'module' object has no attribute 'globals'

Minimal diagnostics:

  • import lua works ok, from python
  • help(lua) work ok, with some methods like getGlobal, but no globals attribute

Environment:

  • Ubuntu 14.04 64bit
  • python 2.7
  • running from a virtualenv

Undefined Symbol problems at load-time in Linux

Hi,

I am trying to use lunatic python to access python code from within lua.
The problem is, whenever I load the python bridge, I get this error:

lua-python.so: undefined symbol: _Py_ZeroStruct

I am running Ubuntu 13.04 and have tried with lua5.1 and lua5.2, both installed with apt and from source with editing loadlib.c to "RTLD_NOW | RTLD_GLOBAL", as suggested by the original author.
I always recompiled lunatic-python to match the current lua version.

Maybe you can help to resolve this issue.
Thank you!

getting lunatic-python to work with luajit

Hi!

I'm trying to use luajit with lunatic-python to access torch from the python side.

I found that I had to make these changes:

  • in setup.py, add 'luajit' to the pkgconfig call:

lua_pkgconfig = pkgconfig('luajit', 'lua', 'lua' + LUAVERSION,'python-' + PYTHONVERSION)

instead of

lua_pkgconfig = pkgconfig('lua', 'lua' + LUAVERSION,'python-' + PYTHONVERSION)

  • before trying to 'require' packages in lua, load the luajit shared-object with exported symbols:

import ctypes
lualib = ctypes.CDLL("libluajit-5.1.so", mode=ctypes.RTLD_GLOBAL)

After which, I can:

lua.execute('require "torch"')

My question is: can anybody suggest a good way to integrate these changes into the repo, so that future users don't have to do this little dance?

Won't build under Ubuntu 11.10

Trying to build this under Ubuntu 11.10 with Python 2.7 and Lua 5.1, I get:

building 'lua-python' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/pythoninlua.c -o build/temp.linux-x86_64-2.7/src/pythoninlua.o -rdynamic -I/usr/include/lua5.1 src/pythoninlua.c: In function ‘py_convert’: src/pythoninlua.c:74:3: warning: passing argument 3 of ‘PyString_AsStringAndSize’ from incompatible pointer type [enabled by default] /usr/include/python2.7/stringobject.h:172:17: note: expected ‘Py_ssize_t *’ but argument is of type ‘int *’ src/pythoninlua.c: In function ‘py_object_tostring’: src/pythoninlua.c:335:4: warning: passing argument 3 of ‘PyString_AsStringAndSize’ from incompatible pointer type [enabled by default] /usr/include/python2.7/stringobject.h:172:17: note: expected ‘Py_ssize_t *’ but argument is of type ‘int *’ gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/luainpython.c -o build/temp.linux-x86_64-2.7/src/luainpython.o -rdynamic -I/usr/include/lua5.1 src/luainpython.c:345:2: warning: initialization from incompatible pointer type [enabled by default] src/luainpython.c:345:2: warning: (near initialization for ‘LuaObject_as_mapping.mp_length’) [enabled by default] src/luainpython.c: In function ‘initlua’: src/luainpython.c:496:3: warning: implicit declaration of function ‘luaopen_loadlib’ [-Wimplicit-function-declaration] src/luainpython.c:486:12: warning: variable ‘m’ set but not used [-Wunused-but-set-variable] creating build/lib.linux-x86_64-2.7 gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions build/temp.linux-x86_64-2.7/src/pythoninlua.o build/temp.linux-x86_64-2.7/src/luainpython.o -L/usr/lib/python2.7/config -lpython2.7 -lpthread -lutil -o build/lib.linux-x86_64-2.7/lua-python.so -rdynamic -I/usr/include/lua5.1 building 'lua' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/pythoninlua.c -o build/temp.linux-x86_64-2.7/src/pythoninlua.o -rdynamic -I/usr/include/lua5.1 src/pythoninlua.c: In function ‘py_convert’: src/pythoninlua.c:74:3: warning: passing argument 3 of ‘PyString_AsStringAndSize’ from incompatible pointer type [enabled by default] /usr/include/python2.7/stringobject.h:172:17: note: expected ‘Py_ssize_t *’ but argument is of type ‘int *’ src/pythoninlua.c: In function ‘py_object_tostring’: src/pythoninlua.c:335:4: warning: passing argument 3 of ‘PyString_AsStringAndSize’ from incompatible pointer type [enabled by default] /usr/include/python2.7/stringobject.h:172:17: note: expected ‘Py_ssize_t *’ but argument is of type ‘int *’ gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/luainpython.c -o build/temp.linux-x86_64-2.7/src/luainpython.o -rdynamic -I/usr/include/lua5.1 src/luainpython.c:345:2: warning: initialization from incompatible pointer type [enabled by default] src/luainpython.c:345:2: warning: (near initialization for ‘LuaObject_as_mapping.mp_length’) [enabled by default] src/luainpython.c: In function ‘initlua’: src/luainpython.c:496:3: warning: implicit declaration of function ‘luaopen_loadlib’ [-Wimplicit-function-declaration] src/luainpython.c:486:12: warning: variable ‘m’ set but not used [-Wunused-but-set-variable] gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions build/temp.linux-x86_64-2.7/src/pythoninlua.o build/temp.linux-x86_64-2.7/src/luainpython.o -llua -llualib -o build/lib.linux-x86_64-2.7/lua.so -rdynamic -I/usr/include/lua5.1 /usr/bin/ld: cannot find -llua /usr/bin/ld: cannot find -llualib collect2: ld returned 1 exit status error: command 'gcc' failed with exit status 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.