Skip to content

Unable to get the exception string from a python function #86

Description

@sudheerhebbale

First of all this is an excellent library and very useful, thanks for this.

While calling a function in a python module from a lua module, if the called python function throws an exception, the exception gets printed on STDERR, however it will be better if the same is printed along with luaL_error

I tried modifying code pythoninlua.c in the function py_object_call it works OK

Please consider making changes to this effect.

        PyObject *exc_type, *exc_value, *exc_traceback;
        PyErr_Fetch(&exc_type, &exc_value, &exc_traceback);
        PyObject *exc_str = PyObject_Str(exc_value);
        const char *exc_cstr = PyUnicode_AsUTF8(exc_str);
        exc_cstr = (!exc_cstr)? "ERROR": exc_cstr;
        luaL_error(L, "error calling python function [%s]", exc_cstr);

Note: Cleaning up memory with DECREF etc. is not taken care in the example

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions