-
-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added option to pass already created LuaState #224
base: master
Are you sure you want to change the base?
Conversation
Mind adding some tests? |
Thanks. I don't think it's that easy, though. Lupa assumes that it owns the Another thing is that It's also unclear to me what you are passing into the constructor here. Is it the pointer address of the I'm not generally opposed to such an interface, but then it should be provided as a C-level API and not be made publicly available to Python programs. An example of your own usage could help to understand how you intend this to work. |
Sorry for long response, I was bit busy on work.
I've added flag
I've reworked it in 32fd682. Now
But all initialization LuaRuntime done in
When reworked my code I've added Cython proxy module in new commit 32fd682. You could find complete code in embedded.pyx Also I've added code in require "libpylua"
python.import("some_package")
python.exec("some_var = some_package.somefunction()") python.import added in 78f4b16 |
Idea: we can add an internal extension type ( cdef class _ExternalLuaState:
lua_State* lua_state
cdef api runtime_from_lua_state(lua_State* lua_state):
cdef _ExternalLuaState arg = _ExternalLuaState.__new__(_ExternalLuaState)
arg.lua_state = lua_state
return LuaRuntime(lua_state=arg) |
LUA_ENTRY_POINT(libpylua) { | ||
PyImport_AppendInittab("embedded", PyInit_embedded); | ||
Py_Initialize(); | ||
PyImport_ImportModule("embedded"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'd better add some checks here, e.g.
PyObject *mod = PyImport_ImportModule("embedded");
if (mod==NULL)
{
PyErr_Print();
}
else
{
Py_DECREF(mod);
}
Hello, I stumble upon limitation of lupa library.
I some cases already created
lua_State
required to be used. But there is no possibility to pass pointer tolua_State
inLuaRuntime
. For example Wireshark has embedded Lua interpreter and this interpreter has bindings to Wireshark API. I wanted to write plugin (dissector) using Python because it is much more convenient than Lua for me (a lot libraries, familiar syntax, good IDE, etc). So it is not very hard to start Python interpreter using simple Lua C extensions module but without wrappers like lupa provided, I need to also write these wrappers by myself. So I wrote this simple patch to pass pointer of Lua interpreter intoLuaRuntime
and it works! I think may be it worth to be added to your library.Regards