/* Generated by Cython 0.13pre on Tue Jul 13 23:52:23 2010 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#else

#include <stddef.h> /* For offsetof */
#ifndef offsetof
#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif

#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif

#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif

#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif

#if PY_VERSION_HEX < 0x02040000
  #define METH_COEXIST 0
  #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
  #define PyDict_Contains(d,o)   PySequence_Contains(d,o)
#endif

#if PY_VERSION_HEX < 0x02050000
  typedef int Py_ssize_t;
  #define PY_SSIZE_T_MAX INT_MAX
  #define PY_SSIZE_T_MIN INT_MIN
  #define PY_FORMAT_SIZE_T ""
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)   PyInt_AsLong(o)
  #define PyNumber_Index(o)    PyNumber_Int(o)
  #define PyIndex_Check(o)     PyNumber_Check(o)
  #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
#endif

#if PY_VERSION_HEX < 0x02060000
  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
  #define PyVarObject_HEAD_INIT(type, size) \
          PyObject_HEAD_INIT(type) size,
  #define PyType_Modified(t)

  typedef struct {
     void *buf;
     PyObject *obj;
     Py_ssize_t len;
     Py_ssize_t itemsize;
     int readonly;
     int ndim;
     char *format;
     Py_ssize_t *shape;
     Py_ssize_t *strides;
     Py_ssize_t *suboffsets;
     void *internal;
  } Py_buffer;

  #define PyBUF_SIMPLE 0
  #define PyBUF_WRITABLE 0x0001
  #define PyBUF_FORMAT 0x0004
  #define PyBUF_ND 0x0008
  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)

#endif

#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
#endif

#if PY_MAJOR_VERSION >= 3
  #define Py_TPFLAGS_CHECKTYPES 0
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif

#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#endif

#if PY_VERSION_HEX < 0x02060000
  #define PyBytesObject                PyStringObject
  #define PyBytes_Type                 PyString_Type
  #define PyBytes_Check                PyString_Check
  #define PyBytes_CheckExact           PyString_CheckExact
  #define PyBytes_FromString           PyString_FromString
  #define PyBytes_FromStringAndSize    PyString_FromStringAndSize
  #define PyBytes_FromFormat           PyString_FromFormat
  #define PyBytes_DecodeEscape         PyString_DecodeEscape
  #define PyBytes_AsString             PyString_AsString
  #define PyBytes_AsStringAndSize      PyString_AsStringAndSize
  #define PyBytes_Size                 PyString_Size
  #define PyBytes_AS_STRING            PyString_AS_STRING
  #define PyBytes_GET_SIZE             PyString_GET_SIZE
  #define PyBytes_Repr                 PyString_Repr
  #define PyBytes_Concat               PyString_Concat
  #define PyBytes_ConcatAndDel         PyString_ConcatAndDel
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
#endif

#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyMethod_New(func, self, klass) PyInstanceMethod_New(func)
#endif

#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
#else
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
#endif

#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_NAMESTR(n) ((char *)(n))
  #define __Pyx_DOCSTR(n)  ((char *)(n))
#else
  #define __Pyx_NAMESTR(n) (n)
  #define __Pyx_DOCSTR(n)  (n)
#endif

#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif

#if defined(WIN32) || defined(MS_WINDOWS)
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#define __PYX_HAVE_API__lupa___lupa
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "stdio.h"
#include "pythread.h"

/* inline attribute */
#ifndef CYTHON_INLINE
  #if defined(__GNUC__)
    #define CYTHON_INLINE __inline__
  #elif defined(_MSC_VER)
    #define CYTHON_INLINE __inline
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_INLINE inline
  #else
    #define CYTHON_INLINE 
  #endif
#endif

/* unused attribute */
#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define CYTHON_UNUSED __attribute__ ((__unused__)) 
#   else
#     define CYTHON_UNUSED
#   endif
# elif defined(__ICC) || defined(__INTEL_COMPILER)
#   define CYTHON_UNUSED __attribute__ ((__unused__)) 
# else
#   define CYTHON_UNUSED 
# endif
#endif

typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/


/* Type Conversion Predeclarations */

#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s)
#define __Pyx_PyBytes_AsUString(s)   ((unsigned char*) PyBytes_AsString(s))

#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);

static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);

#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))


#ifdef __GNUC__
/* Test for GCC > 2.95 */
#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) 
#define likely(x)   __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else /* __GNUC__ > 2 ... */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ > 2 ... */
#else /* __GNUC__ */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ */
    
static PyObject *__pyx_m;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;
static const char **__pyx_f;


/* Type declarations */

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":20
 * cdef class _LuaObject
 * 
 * cdef struct py_object:             # <<<<<<<<<<<<<<
 *     PyObject* obj
 *     PyObject* runtime
 */

struct __pyx_t_4lupa_5_lupa_py_object {
  PyObject *obj;
  PyObject *runtime;
  int as_index;
};

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":18
 * DEF POBJECT = "POBJECT" # as used by LunaticPython
 * 
 * cdef class _LuaObject             # <<<<<<<<<<<<<<
 * 
 * cdef struct py_object:
 */

struct __pyx_obj_4lupa_5_lupa__LuaObject {
  PyObject_HEAD
  struct __pyx_obj_4lupa_5_lupa_LuaRuntime *_runtime;
  int _ref;
  int _refiter;
};

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":36
 *     pass
 * 
 * cdef class LuaRuntime:             # <<<<<<<<<<<<<<
 *     """The main entry point to the Lua runtime.
 * 
 */

struct __pyx_obj_4lupa_5_lupa_LuaRuntime {
  PyObject_HEAD
  struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime *__pyx_vtab;
  lua_State *_state;
  PyThread_type_lock _thread_lock;
  PyObject *_raised_exception;
};


struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime {
  int (*lock)(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *);
  void (*unlock)(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *);
  int (*reraise_on_exception)(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *);
  int (*store_raised_exception)(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *);
  int (*register_py_object)(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *, PyObject *, PyObject *, PyObject *);
  int (*init_python_lib)(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *);
};
static struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime *__pyx_vtabptr_4lupa_5_lupa_LuaRuntime;

#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif

#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct * __Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
  end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
  }
  #define __Pyx_RefNannySetupContext(name)           void *__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
  #define __Pyx_RefNannyFinishContext()           __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0)
#else
  #define __Pyx_RefNannySetupContext(name)
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
#endif /* CYTHON_REFNANNY */
#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);} } while(0)
#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r);} } while(0)

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/

static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/

static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict,
    const char* function_name, int kw_allowed); /*proto*/


static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}


#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_List_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
            PyObject *r = PyList_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Tuple_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}


#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) {
    PyObject *r;
    if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
    }
    else if (PyTuple_CheckExact(o) && ((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
    }
    else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_item && (likely(i >= 0))) {
        r = PySequence_GetItem(o, i);
    }
    else {
        r = __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
    }
    return r;
}

static CYTHON_INLINE PyObject* __Pyx_tp_new(PyObject* type_obj) {
    return (PyObject*) (((PyTypeObject*)(type_obj))->tp_new(
        (PyTypeObject*)(type_obj), __pyx_empty_tuple, NULL));
}

static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

#include <string.h>

static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/

static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, const char *modname); /*proto*/

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/

#ifndef __PYX_FORCE_INIT_THREADS
  #if PY_VERSION_HEX < 0x02040200
    #define __PYX_FORCE_INIT_THREADS 1
  #else
    #define __PYX_FORCE_INIT_THREADS 0
  #endif
#endif

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);

static void __Pyx_WriteUnraisable(const char *name); /*proto*/

static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/

static void __Pyx_AddTraceback(const char *funcname); /*proto*/

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
/* Module declarations from lupa.lua */

/* Module declarations from cpython.version */

/* Module declarations from cpython.ref */

/* Module declarations from cpython.exc */

/* Module declarations from cpython.module */

/* Module declarations from cpython.mem */

/* Module declarations from cpython.tuple */

/* Module declarations from cpython.list */

/* Module declarations from libc.stdio */

/* Module declarations from cpython.object */

/* Module declarations from cpython.sequence */

/* Module declarations from cpython.mapping */

/* Module declarations from cpython.iterator */

/* Module declarations from cpython.type */

/* Module declarations from cpython.number */

/* Module declarations from cpython.int */

/* Module declarations from cpython.bool */

/* Module declarations from cpython.long */

/* Module declarations from cpython.float */

/* Module declarations from cpython.complex */

/* Module declarations from cpython.string */

/* Module declarations from cpython.unicode */

/* Module declarations from cpython.dict */

/* Module declarations from cpython.instance */

/* Module declarations from cpython.function */

/* Module declarations from cpython.method */

/* Module declarations from cpython.weakref */

/* Module declarations from cpython.getargs */

/* Module declarations from cpython.pythread */

/* Module declarations from cpython.cobject */

/* Module declarations from cpython.oldbuffer */

/* Module declarations from cpython.set */

/* Module declarations from cpython.buffer */

/* Module declarations from cpython.bytes */

/* Module declarations from cpython.pycapsule */

/* Module declarations from cpython */

/* Module declarations from lupa._lupa */

static PyTypeObject *__pyx_ptype_4lupa_5_lupa__LuaObject = 0;
static PyTypeObject *__pyx_ptype_4lupa_5_lupa_LuaRuntime = 0;
static PyObject *__pyx_v_4lupa_5_lupa_exc_info = 0;
static luaL_Reg __pyx_v_4lupa_5_lupa_py_object_lib[6];
static luaL_Reg __pyx_v_4lupa_5_lupa_py_lib[6];
static struct __pyx_obj_4lupa_5_lupa__LuaObject *__pyx_f_4lupa_5_lupa_new_lua_object(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *, int); /*proto*/
static int __pyx_f_4lupa_5_lupa_py_asfunc_call(lua_State *); /*proto*/
static PyObject *__pyx_f_4lupa_5_lupa_py_from_lua(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *, int); /*proto*/
static int __pyx_f_4lupa_5_lupa_py_to_lua(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *, PyObject *, int); /*proto*/
static int __pyx_f_4lupa_5_lupa_py_to_lua_custom(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *, PyObject *, int); /*proto*/
static PyObject *__pyx_f_4lupa_5_lupa_run_lua(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *, PyObject *); /*proto*/
static PyObject *__pyx_f_4lupa_5_lupa_call_lua(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *, PyObject *); /*proto*/
static void __pyx_f_4lupa_5_lupa_decref_with_gil(struct __pyx_t_4lupa_5_lupa_py_object *); /*proto*/
static int __pyx_f_4lupa_5_lupa_py_object_gc(lua_State *); /*proto*/
static int __pyx_f_4lupa_5_lupa_call_python(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *, struct __pyx_t_4lupa_5_lupa_py_object *); /*proto*/
static int __pyx_f_4lupa_5_lupa_py_call_with_gil(lua_State *, struct __pyx_t_4lupa_5_lupa_py_object *); /*proto*/
static int __pyx_f_4lupa_5_lupa_py_object_call(lua_State *); /*proto*/
static int __pyx_f_4lupa_5_lupa_py_str_with_gil(lua_State *, struct __pyx_t_4lupa_5_lupa_py_object *); /*proto*/
static int __pyx_f_4lupa_5_lupa_py_object_str(lua_State *); /*proto*/
#define __Pyx_MODULE_NAME "lupa._lupa"
int __pyx_module_is_main_lupa___lupa = 0;

/* Implementation of lupa._lupa */
static PyObject *__pyx_builtin_Exception;
static PyObject *__pyx_builtin_eval;
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_UnicodeDecodeError;
static PyObject *__pyx_builtin_enumerate;
static PyObject *__pyx_builtin_range;
static char __pyx_k_1[] = "Failed to initialise Lua runtime";
static char __pyx_k_2[] = "Failed to initialise thread lock";
static char __pyx_k_3[] = "Failed to acquire thread lock";
static char __pyx_k_4[] = "return ";
static char __pyx_k_5[] = "failed to convert %s object";
static char __pyx_k_6[] = "Type cannot be instantiated manually";
static char __pyx_k_7[] = "<Lua %s at %p>";
static char __pyx_k_8[] = "<Lua %s>";
static char __pyx_k_9[] = "UTF-8";
static char __pyx_k_10[] = "ISO-8859-1";
static char __pyx_k_11[] = "lost reference";
static char __pyx_k_12[] = "lost none from registry";
static char __pyx_k_13[] = "cannot mix objects from different Lua runtimes";
static char __pyx_k_14[] = "failed to allocate userdata object";
static char __pyx_k_15[] = "<python>";
static char __pyx_k_16[] = "error loading code: %s";
static char __pyx_k_17[] = "reraise_on_exception";
static char __pyx_k_18[] = "error executing code: %s";
static char __pyx_k_19[] = "failed to convert argument at index %d";
static char __pyx_k_20[] = "error: %s";
static char __pyx_k_21[] = "not a python object";
static char __pyx_k_22[] = "store_raised_exception";
static char __pyx_k_23[] = "error during Python call: %r";
static char __pyx_k_24[] = "error during Python call";
static char __pyx_k_25[] = "error during Python str() call: %r";
static char __pyx_k_26[] = "error during Python str() call";
static char __pyx_k__obj[] = "obj";
static char __pyx_k__sys[] = "sys";
static char __pyx_k____gc[] = "__gc";
static char __pyx_k___ref[] = "_ref";
static char __pyx_k__eval[] = "eval";
static char __pyx_k__func[] = "func";
static char __pyx_k__lock[] = "lock";
static char __pyx_k__name[] = "name";
static char __pyx_k__none[] = "none";
static char __pyx_k__ASCII[] = "ASCII";
static char __pyx_k__range[] = "range";
static char __pyx_k____call[] = "__call";
static char __pyx_k___state[] = "_state";
static char __pyx_k__decode[] = "decode";
static char __pyx_k__encode[] = "encode";
static char __pyx_k__python[] = "python";
static char __pyx_k__unlock[] = "unlock";
static char __pyx_k__POBJECT[] = "POBJECT";
static char __pyx_k__Py_None[] = "Py_None";
static char __pyx_k____all__[] = "__all__";
static char __pyx_k__runtime[] = "runtime";
static char __pyx_k__LuaError[] = "LuaError";
static char __pyx_k____call__[] = "__call__";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____test__[] = "__test__";
static char __pyx_k___refiter[] = "_refiter";
static char __pyx_k___runtime[] = "_runtime";
static char __pyx_k__as_index[] = "as_index";
static char __pyx_k__exc_info[] = "exc_info";
static char __pyx_k__Exception[] = "Exception";
static char __pyx_k__TypeError[] = "TypeError";
static char __pyx_k__enumerate[] = "enumerate";
static char __pyx_k__LuaRuntime[] = "LuaRuntime";
static char __pyx_k____tostring[] = "__tostring";
static char __pyx_k___thread_lock[] = "_thread_lock";
static char __pyx_k__init_python_lib[] = "init_python_lib";
static char __pyx_k___raised_exception[] = "_raised_exception";
static char __pyx_k__UnicodeDecodeError[] = "UnicodeDecodeError";
static char __pyx_k__register_py_object[] = "register_py_object";
static PyObject *__pyx_kp_s_1;
static PyObject *__pyx_kp_s_10;
static PyObject *__pyx_kp_s_11;
static PyObject *__pyx_kp_s_13;
static PyObject *__pyx_kp_s_16;
static PyObject *__pyx_n_s_17;
static PyObject *__pyx_kp_s_18;
static PyObject *__pyx_kp_s_19;
static PyObject *__pyx_kp_s_2;
static PyObject *__pyx_kp_s_20;
static PyObject *__pyx_n_s_22;
static PyObject *__pyx_kp_u_23;
static PyObject *__pyx_kp_u_25;
static PyObject *__pyx_kp_s_3;
static PyObject *__pyx_kp_b_4;
static PyObject *__pyx_kp_b_5;
static PyObject *__pyx_kp_s_6;
static PyObject *__pyx_kp_s_9;
static PyObject *__pyx_n_s__ASCII;
static PyObject *__pyx_n_s__Exception;
static PyObject *__pyx_n_s__LuaError;
static PyObject *__pyx_n_s__LuaRuntime;
static PyObject *__pyx_n_s__Py_None;
static PyObject *__pyx_n_s__TypeError;
static PyObject *__pyx_n_s__UnicodeDecodeError;
static PyObject *__pyx_n_s____all__;
static PyObject *__pyx_n_s____call__;
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____test__;
static PyObject *__pyx_n_s___raised_exception;
static PyObject *__pyx_n_s___ref;
static PyObject *__pyx_n_s___refiter;
static PyObject *__pyx_n_s___runtime;
static PyObject *__pyx_n_s___state;
static PyObject *__pyx_n_s___thread_lock;
static PyObject *__pyx_n_s__as_index;
static PyObject *__pyx_n_s__decode;
static PyObject *__pyx_n_s__encode;
static PyObject *__pyx_n_s__enumerate;
static PyObject *__pyx_n_s__eval;
static PyObject *__pyx_n_s__exc_info;
static PyObject *__pyx_n_s__func;
static PyObject *__pyx_n_s__init_python_lib;
static PyObject *__pyx_n_s__lock;
static PyObject *__pyx_n_s__name;
static PyObject *__pyx_n_s__none;
static PyObject *__pyx_n_s__obj;
static PyObject *__pyx_n_s__range;
static PyObject *__pyx_n_s__register_py_object;
static PyObject *__pyx_n_s__runtime;
static PyObject *__pyx_n_s__sys;
static PyObject *__pyx_n_s__unlock;
static PyObject *__pyx_int_2;

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":56
 *     cdef tuple _raised_exception
 * 
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         self._thread_lock = self._state = NULL
 *         cdef lua_State* L = lua.lua_open()
 */

static int __pyx_pf_4lupa_5_lupa_10LuaRuntime___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_4lupa_5_lupa_10LuaRuntime___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  lua_State *__pyx_v_L;
  int __pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  __Pyx_RefNannySetupContext("__cinit__");
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1;
  __Pyx_INCREF((PyObject *)__pyx_v_self);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":57
 * 
 *     def __cinit__(self):
 *         self._thread_lock = self._state = NULL             # <<<<<<<<<<<<<<
 *         cdef lua_State* L = lua.lua_open()
 *         if L is NULL:
 */
  ((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_self)->_thread_lock = NULL;
  ((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_self)->_state = NULL;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":58
 *     def __cinit__(self):
 *         self._thread_lock = self._state = NULL
 *         cdef lua_State* L = lua.lua_open()             # <<<<<<<<<<<<<<
 *         if L is NULL:
 *             raise LuaError("Failed to initialise Lua runtime")
 */
  __pyx_v_L = lua_open();

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":59
 *         self._thread_lock = self._state = NULL
 *         cdef lua_State* L = lua.lua_open()
 *         if L is NULL:             # <<<<<<<<<<<<<<
 *             raise LuaError("Failed to initialise Lua runtime")
 *         self._state = L
 */
  __pyx_t_1 = (__pyx_v_L == NULL);
  if (__pyx_t_1) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":60
 *         cdef lua_State* L = lua.lua_open()
 *         if L is NULL:
 *             raise LuaError("Failed to initialise Lua runtime")             # <<<<<<<<<<<<<<
 *         self._state = L
 * 
 */
    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__LuaError); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_1));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
    __pyx_t_4 = PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":61
 *         if L is NULL:
 *             raise LuaError("Failed to initialise Lua runtime")
 *         self._state = L             # <<<<<<<<<<<<<<
 * 
 *         self._thread_lock = pythread.PyThread_allocate_lock()
 */
  ((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_self)->_state = __pyx_v_L;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":63
 *         self._state = L
 * 
 *         self._thread_lock = pythread.PyThread_allocate_lock()             # <<<<<<<<<<<<<<
 *         if self._thread_lock is NULL:
 *             raise LuaError("Failed to initialise thread lock")
 */
  ((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_self)->_thread_lock = PyThread_allocate_lock();

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":64
 * 
 *         self._thread_lock = pythread.PyThread_allocate_lock()
 *         if self._thread_lock is NULL:             # <<<<<<<<<<<<<<
 *             raise LuaError("Failed to initialise thread lock")
 * 
 */
  __pyx_t_1 = (((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_self)->_thread_lock == NULL);
  if (__pyx_t_1) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":65
 *         self._thread_lock = pythread.PyThread_allocate_lock()
 *         if self._thread_lock is NULL:
 *             raise LuaError("Failed to initialise thread lock")             # <<<<<<<<<<<<<<
 * 
 *         lua.luaopen_base(L)
 */
    __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__LuaError); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_2));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_2));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_2));
    __pyx_t_2 = PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":67
 *             raise LuaError("Failed to initialise thread lock")
 * 
 *         lua.luaopen_base(L)             # <<<<<<<<<<<<<<
 *         lua.luaopen_table(L)
 *         lua.luaopen_io(L)
 */
  luaopen_base(__pyx_v_L);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":68
 * 
 *         lua.luaopen_base(L)
 *         lua.luaopen_table(L)             # <<<<<<<<<<<<<<
 *         lua.luaopen_io(L)
 *         lua.luaopen_string(L)
 */
  luaopen_table(__pyx_v_L);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":69
 *         lua.luaopen_base(L)
 *         lua.luaopen_table(L)
 *         lua.luaopen_io(L)             # <<<<<<<<<<<<<<
 *         lua.luaopen_string(L)
 *         lua.luaopen_debug(L)
 */
  luaopen_io(__pyx_v_L);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":70
 *         lua.luaopen_table(L)
 *         lua.luaopen_io(L)
 *         lua.luaopen_string(L)             # <<<<<<<<<<<<<<
 *         lua.luaopen_debug(L)
 *         #lua.luaopen_loadlib(L)
 */
  luaopen_string(__pyx_v_L);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":71
 *         lua.luaopen_io(L)
 *         lua.luaopen_string(L)
 *         lua.luaopen_debug(L)             # <<<<<<<<<<<<<<
 *         #lua.luaopen_loadlib(L)
 *         self.init_python_lib()
 */
  luaopen_debug(__pyx_v_L);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":73
 *         lua.luaopen_debug(L)
 *         #lua.luaopen_loadlib(L)
 *         self.init_python_lib()             # <<<<<<<<<<<<<<
 *         lua.lua_settop(L, 0)
 * 
 */
  __pyx_t_5 = ((struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime *)((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_self)->__pyx_vtab)->init_python_lib(((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_self)); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":74
 *         #lua.luaopen_loadlib(L)
 *         self.init_python_lib()
 *         lua.lua_settop(L, 0)             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  lua_settop(__pyx_v_L, 0);

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("lupa._lupa.LuaRuntime.__cinit__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":76
 *         lua.lua_settop(L, 0)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         if self._state is not NULL:
 *             lua.lua_close(self._state)
 */

static void __pyx_pf_4lupa_5_lupa_10LuaRuntime___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pf_4lupa_5_lupa_10LuaRuntime___dealloc__(PyObject *__pyx_v_self) {
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__dealloc__");
  __Pyx_INCREF((PyObject *)__pyx_v_self);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":77
 * 
 *     def __dealloc__(self):
 *         if self._state is not NULL:             # <<<<<<<<<<<<<<
 *             lua.lua_close(self._state)
 *             self._state = NULL
 */
  __pyx_t_1 = (((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_self)->_state != NULL);
  if (__pyx_t_1) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":78
 *     def __dealloc__(self):
 *         if self._state is not NULL:
 *             lua.lua_close(self._state)             # <<<<<<<<<<<<<<
 *             self._state = NULL
 *         if self._thread_lock is not NULL:
 */
    lua_close(((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_self)->_state);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":79
 *         if self._state is not NULL:
 *             lua.lua_close(self._state)
 *             self._state = NULL             # <<<<<<<<<<<<<<
 *         if self._thread_lock is not NULL:
 *             pythread.PyThread_free_lock(self._thread_lock)
 */
    ((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_self)->_state = NULL;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":80
 *             lua.lua_close(self._state)
 *             self._state = NULL
 *         if self._thread_lock is not NULL:             # <<<<<<<<<<<<<<
 *             pythread.PyThread_free_lock(self._thread_lock)
 *             self._thread_lock = NULL
 */
  __pyx_t_1 = (((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_self)->_thread_lock != NULL);
  if (__pyx_t_1) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":81
 *             self._state = NULL
 *         if self._thread_lock is not NULL:
 *             pythread.PyThread_free_lock(self._thread_lock)             # <<<<<<<<<<<<<<
 *             self._thread_lock = NULL
 * 
 */
    PyThread_free_lock(((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_self)->_thread_lock);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":82
 *         if self._thread_lock is not NULL:
 *             pythread.PyThread_free_lock(self._thread_lock)
 *             self._thread_lock = NULL             # <<<<<<<<<<<<<<
 * 
 *     cdef int lock(self) except -1:
 */
    ((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_self)->_thread_lock = NULL;
    goto __pyx_L6;
  }
  __pyx_L6:;

  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_RefNannyFinishContext();
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":84
 *             self._thread_lock = NULL
 * 
 *     cdef int lock(self) except -1:             # <<<<<<<<<<<<<<
 *         with nogil:
 *             locked = pythread.PyThread_acquire_lock(self._thread_lock, pythread.WAIT_LOCK)
 */

static  int __pyx_f_4lupa_5_lupa_10LuaRuntime_lock(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *__pyx_v_self) {
  int __pyx_v_locked;
  int __pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_RefNannySetupContext("lock");
  __Pyx_INCREF((PyObject *)__pyx_v_self);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":85
 * 
 *     cdef int lock(self) except -1:
 *         with nogil:             # <<<<<<<<<<<<<<
 *             locked = pythread.PyThread_acquire_lock(self._thread_lock, pythread.WAIT_LOCK)
 *         if not locked:
 */
  { PyThreadState *_save;
    Py_UNBLOCK_THREADS
    /*try:*/ {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":86
 *     cdef int lock(self) except -1:
 *         with nogil:
 *             locked = pythread.PyThread_acquire_lock(self._thread_lock, pythread.WAIT_LOCK)             # <<<<<<<<<<<<<<
 *         if not locked:
 *             raise LuaError("Failed to acquire thread lock")
 */
      __pyx_v_locked = PyThread_acquire_lock(__pyx_v_self->_thread_lock, WAIT_LOCK);
    }
    /*finally:*/ {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":85
 * 
 *     cdef int lock(self) except -1:
 *         with nogil:             # <<<<<<<<<<<<<<
 *             locked = pythread.PyThread_acquire_lock(self._thread_lock, pythread.WAIT_LOCK)
 *         if not locked:
 */
      Py_BLOCK_THREADS
    }
  }

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":87
 *         with nogil:
 *             locked = pythread.PyThread_acquire_lock(self._thread_lock, pythread.WAIT_LOCK)
 *         if not locked:             # <<<<<<<<<<<<<<
 *             raise LuaError("Failed to acquire thread lock")
 *         return 0
 */
  __pyx_t_1 = (!__pyx_v_locked);
  if (__pyx_t_1) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":88
 *             locked = pythread.PyThread_acquire_lock(self._thread_lock, pythread.WAIT_LOCK)
 *         if not locked:
 *             raise LuaError("Failed to acquire thread lock")             # <<<<<<<<<<<<<<
 *         return 0
 * 
 */
    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__LuaError); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_3));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3));
    __pyx_t_4 = PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":89
 *         if not locked:
 *             raise LuaError("Failed to acquire thread lock")
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef void unlock(self) nogil:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("lupa._lupa.LuaRuntime.lock");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":91
 *         return 0
 * 
 *     cdef void unlock(self) nogil:             # <<<<<<<<<<<<<<
 *         pythread.PyThread_release_lock(self._thread_lock)
 * 
 */

static  void __pyx_f_4lupa_5_lupa_10LuaRuntime_unlock(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *__pyx_v_self) {

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":92
 * 
 *     cdef void unlock(self) nogil:
 *         pythread.PyThread_release_lock(self._thread_lock)             # <<<<<<<<<<<<<<
 * 
 *     cdef int reraise_on_exception(self) except -1:
 */
  PyThread_release_lock(__pyx_v_self->_thread_lock);

}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":94
 *         pythread.PyThread_release_lock(self._thread_lock)
 * 
 *     cdef int reraise_on_exception(self) except -1:             # <<<<<<<<<<<<<<
 *         if self._raised_exception is not None:
 *             exception = self._raised_exception
 */

static  int __pyx_f_4lupa_5_lupa_10LuaRuntime_reraise_on_exception(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *__pyx_v_self) {
  PyObject *__pyx_v_exception;
  int __pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_RefNannySetupContext("reraise_on_exception");
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __pyx_v_exception = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":95
 * 
 *     cdef int reraise_on_exception(self) except -1:
 *         if self._raised_exception is not None:             # <<<<<<<<<<<<<<
 *             exception = self._raised_exception
 *             self._raised_exception = None
 */
  __pyx_t_1 = (__pyx_v_self->_raised_exception != ((PyObject *)Py_None));
  if (__pyx_t_1) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":96
 *     cdef int reraise_on_exception(self) except -1:
 *         if self._raised_exception is not None:
 *             exception = self._raised_exception             # <<<<<<<<<<<<<<
 *             self._raised_exception = None
 *             raise exception[0], exception[1], exception[2]
 */
    __Pyx_INCREF(((PyObject *)__pyx_v_self->_raised_exception));
    __Pyx_DECREF(((PyObject *)__pyx_v_exception));
    __pyx_v_exception = __pyx_v_self->_raised_exception;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":97
 *         if self._raised_exception is not None:
 *             exception = self._raised_exception
 *             self._raised_exception = None             # <<<<<<<<<<<<<<
 *             raise exception[0], exception[1], exception[2]
 *         return 0
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_self->_raised_exception);
    __Pyx_DECREF(((PyObject *)__pyx_v_self->_raised_exception));
    __pyx_v_self->_raised_exception = ((PyObject *)Py_None);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":98
 *             exception = self._raised_exception
 *             self._raised_exception = None
 *             raise exception[0], exception[1], exception[2]             # <<<<<<<<<<<<<<
 *         return 0
 * 
 */
    __pyx_t_2 = __Pyx_GetItemInt_Tuple(((PyObject *)__pyx_v_exception), 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_GetItemInt_Tuple(((PyObject *)__pyx_v_exception), 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_GetItemInt_Tuple(((PyObject *)__pyx_v_exception), 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_2, __pyx_t_3, __pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":99
 *             self._raised_exception = None
 *             raise exception[0], exception[1], exception[2]
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int store_raised_exception(self) except -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("lupa._lupa.LuaRuntime.reraise_on_exception");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_exception);
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":101
 *         return 0
 * 
 *     cdef int store_raised_exception(self) except -1:             # <<<<<<<<<<<<<<
 *         self._raised_exception = exc_info()
 *         return 0
 */

static  int __pyx_f_4lupa_5_lupa_10LuaRuntime_store_raised_exception(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *__pyx_v_self) {
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("store_raised_exception");

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":102
 * 
 *     cdef int store_raised_exception(self) except -1:
 *         self._raised_exception = exc_info()             # <<<<<<<<<<<<<<
 *         return 0
 * 
 */
  __pyx_t_1 = PyObject_Call(__pyx_v_4lupa_5_lupa_exc_info, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyTuple_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected tuple, got %.200s", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->_raised_exception);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->_raised_exception));
  __pyx_v_self->_raised_exception = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":103
 *     cdef int store_raised_exception(self) except -1:
 *         self._raised_exception = exc_info()
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     def eval(self, lua_code):
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("lupa._lupa.LuaRuntime.store_raised_exception");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":105
 *         return 0
 * 
 *     def eval(self, lua_code):             # <<<<<<<<<<<<<<
 *         if isinstance(lua_code, unicode):
 *             lua_code = (<unicode>lua_code).encode('UTF-8')
 */

static PyObject *__pyx_pf_4lupa_5_lupa_10LuaRuntime_eval(PyObject *__pyx_v_self, PyObject *__pyx_v_lua_code); /*proto*/
static PyObject *__pyx_pf_4lupa_5_lupa_10LuaRuntime_eval(PyObject *__pyx_v_self, PyObject *__pyx_v_lua_code) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("eval");
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_lua_code);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":106
 * 
 *     def eval(self, lua_code):
 *         if isinstance(lua_code, unicode):             # <<<<<<<<<<<<<<
 *             lua_code = (<unicode>lua_code).encode('UTF-8')
 *         return run_lua(self, b'return ' + lua_code)
 */
  __pyx_t_1 = PyObject_TypeCheck(__pyx_v_lua_code, ((PyTypeObject *)((PyObject*)&PyUnicode_Type))); 
  if (__pyx_t_1) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":107
 *     def eval(self, lua_code):
 *         if isinstance(lua_code, unicode):
 *             lua_code = (<unicode>lua_code).encode('UTF-8')             # <<<<<<<<<<<<<<
 *         return run_lua(self, b'return ' + lua_code)
 * 
 */
    if (unlikely(((PyObject *)__pyx_v_lua_code) == Py_None)) {
      PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'encode'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
    }
    __pyx_t_2 = ((PyObject *)PyUnicode_AsUTF8String(((PyObject *)__pyx_v_lua_code))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_DECREF(__pyx_v_lua_code);
    __pyx_v_lua_code = ((PyObject *)__pyx_t_2);
    __pyx_t_2 = 0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":108
 *         if isinstance(lua_code, unicode):
 *             lua_code = (<unicode>lua_code).encode('UTF-8')
 *         return run_lua(self, b'return ' + lua_code)             # <<<<<<<<<<<<<<
 * 
 *     def run(self, lua_code):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyNumber_Add(((PyObject *)__pyx_kp_b_4), __pyx_v_lua_code); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __pyx_f_4lupa_5_lupa_run_lua(((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_self), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("lupa._lupa.LuaRuntime.eval");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_lua_code);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":110
 *         return run_lua(self, b'return ' + lua_code)
 * 
 *     def run(self, lua_code):             # <<<<<<<<<<<<<<
 *         if isinstance(lua_code, unicode):
 *             lua_code = (<unicode>lua_code).encode('UTF-8')
 */

static PyObject *__pyx_pf_4lupa_5_lupa_10LuaRuntime_run(PyObject *__pyx_v_self, PyObject *__pyx_v_lua_code); /*proto*/
static PyObject *__pyx_pf_4lupa_5_lupa_10LuaRuntime_run(PyObject *__pyx_v_self, PyObject *__pyx_v_lua_code) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("run");
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_lua_code);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":111
 * 
 *     def run(self, lua_code):
 *         if isinstance(lua_code, unicode):             # <<<<<<<<<<<<<<
 *             lua_code = (<unicode>lua_code).encode('UTF-8')
 *         return run_lua(self, lua_code)
 */
  __pyx_t_1 = PyObject_TypeCheck(__pyx_v_lua_code, ((PyTypeObject *)((PyObject*)&PyUnicode_Type))); 
  if (__pyx_t_1) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":112
 *     def run(self, lua_code):
 *         if isinstance(lua_code, unicode):
 *             lua_code = (<unicode>lua_code).encode('UTF-8')             # <<<<<<<<<<<<<<
 *         return run_lua(self, lua_code)
 * 
 */
    if (unlikely(((PyObject *)__pyx_v_lua_code) == Py_None)) {
      PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'encode'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
    }
    __pyx_t_2 = ((PyObject *)PyUnicode_AsUTF8String(((PyObject *)__pyx_v_lua_code))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_DECREF(__pyx_v_lua_code);
    __pyx_v_lua_code = ((PyObject *)__pyx_t_2);
    __pyx_t_2 = 0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":113
 *         if isinstance(lua_code, unicode):
 *             lua_code = (<unicode>lua_code).encode('UTF-8')
 *         return run_lua(self, lua_code)             # <<<<<<<<<<<<<<
 * 
 *     cdef int register_py_object(self, bytes cname, bytes pyname, object obj) except -1:
 */
  __Pyx_XDECREF(__pyx_r);
  if (!(likely(PyBytes_CheckExact(__pyx_v_lua_code))||((__pyx_v_lua_code) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_lua_code)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __pyx_f_4lupa_5_lupa_run_lua(((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_self), ((PyObject *)__pyx_v_lua_code)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("lupa._lupa.LuaRuntime.run");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_lua_code);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":115
 *         return run_lua(self, lua_code)
 * 
 *     cdef int register_py_object(self, bytes cname, bytes pyname, object obj) except -1:             # <<<<<<<<<<<<<<
 *         cdef lua_State *L = self._state
 *         lua.lua_pushlstring(L, cname, len(cname))
 */

static  int __pyx_f_4lupa_5_lupa_10LuaRuntime_register_py_object(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *__pyx_v_self, PyObject *__pyx_v_cname, PyObject *__pyx_v_pyname, PyObject *__pyx_v_obj) {
  lua_State *__pyx_v_L;
  PyObject *__pyx_v_message;
  int __pyx_r;
  char *__pyx_t_1;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_RefNannySetupContext("register_py_object");
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_cname);
  __Pyx_INCREF(__pyx_v_pyname);
  __Pyx_INCREF(__pyx_v_obj);
  __pyx_v_message = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":116
 * 
 *     cdef int register_py_object(self, bytes cname, bytes pyname, object obj) except -1:
 *         cdef lua_State *L = self._state             # <<<<<<<<<<<<<<
 *         lua.lua_pushlstring(L, cname, len(cname))
 *         if not py_to_lua_custom(self, obj, 0):
 */
  __pyx_v_L = __pyx_v_self->_state;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":117
 *     cdef int register_py_object(self, bytes cname, bytes pyname, object obj) except -1:
 *         cdef lua_State *L = self._state
 *         lua.lua_pushlstring(L, cname, len(cname))             # <<<<<<<<<<<<<<
 *         if not py_to_lua_custom(self, obj, 0):
 *             lua.lua_pop(L, 1)
 */
  __pyx_t_1 = PyBytes_AsString(((PyObject *)__pyx_v_cname)); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(__pyx_v_cname == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
  }
  __pyx_t_2 = PyBytes_GET_SIZE(((PyObject *)__pyx_v_cname)); 
  lua_pushlstring(__pyx_v_L, __pyx_t_1, __pyx_t_2);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":118
 *         cdef lua_State *L = self._state
 *         lua.lua_pushlstring(L, cname, len(cname))
 *         if not py_to_lua_custom(self, obj, 0):             # <<<<<<<<<<<<<<
 *             lua.lua_pop(L, 1)
 *             message = b"failed to convert %s object" % pyname
 */
  __pyx_t_3 = (!__pyx_f_4lupa_5_lupa_py_to_lua_custom(__pyx_v_self, __pyx_v_obj, 0));
  if (__pyx_t_3) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":119
 *         lua.lua_pushlstring(L, cname, len(cname))
 *         if not py_to_lua_custom(self, obj, 0):
 *             lua.lua_pop(L, 1)             # <<<<<<<<<<<<<<
 *             message = b"failed to convert %s object" % pyname
 *             lua.luaL_error(L, message)
 */
    lua_pop(__pyx_v_L, 1);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":120
 *         if not py_to_lua_custom(self, obj, 0):
 *             lua.lua_pop(L, 1)
 *             message = b"failed to convert %s object" % pyname             # <<<<<<<<<<<<<<
 *             lua.luaL_error(L, message)
 *             raise LuaError(message.decode('ASCII'))
 */
    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_b_5), ((PyObject *)__pyx_v_pyname)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_DECREF(((PyObject *)__pyx_v_message));
    __pyx_v_message = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":121
 *             lua.lua_pop(L, 1)
 *             message = b"failed to convert %s object" % pyname
 *             lua.luaL_error(L, message)             # <<<<<<<<<<<<<<
 *             raise LuaError(message.decode('ASCII'))
 *         lua.lua_pushlstring(L, pyname, len(pyname))
 */
    __pyx_t_1 = PyBytes_AsString(((PyObject *)__pyx_v_message)); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    luaL_error(__pyx_v_L, __pyx_t_1);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":122
 *             message = b"failed to convert %s object" % pyname
 *             lua.luaL_error(L, message)
 *             raise LuaError(message.decode('ASCII'))             # <<<<<<<<<<<<<<
 *         lua.lua_pushlstring(L, pyname, len(pyname))
 *         lua.lua_pushvalue(L, -2)
 */
    __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__LuaError); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_message), __pyx_n_s__decode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__ASCII));
    PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_n_s__ASCII));
    __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ASCII));
    __pyx_t_7 = PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_Raise(__pyx_t_7, 0, 0);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":123
 *             lua.luaL_error(L, message)
 *             raise LuaError(message.decode('ASCII'))
 *         lua.lua_pushlstring(L, pyname, len(pyname))             # <<<<<<<<<<<<<<
 *         lua.lua_pushvalue(L, -2)
 *         lua.lua_rawset(L, -5)
 */
  __pyx_t_1 = PyBytes_AsString(((PyObject *)__pyx_v_pyname)); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(__pyx_v_pyname == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
  }
  __pyx_t_2 = PyBytes_GET_SIZE(((PyObject *)__pyx_v_pyname)); 
  lua_pushlstring(__pyx_v_L, __pyx_t_1, __pyx_t_2);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":124
 *             raise LuaError(message.decode('ASCII'))
 *         lua.lua_pushlstring(L, pyname, len(pyname))
 *         lua.lua_pushvalue(L, -2)             # <<<<<<<<<<<<<<
 *         lua.lua_rawset(L, -5)
 *         lua.lua_rawset(L, lua.LUA_REGISTRYINDEX)
 */
  lua_pushvalue(__pyx_v_L, -2);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":125
 *         lua.lua_pushlstring(L, pyname, len(pyname))
 *         lua.lua_pushvalue(L, -2)
 *         lua.lua_rawset(L, -5)             # <<<<<<<<<<<<<<
 *         lua.lua_rawset(L, lua.LUA_REGISTRYINDEX)
 *         return 0
 */
  lua_rawset(__pyx_v_L, -5);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":126
 *         lua.lua_pushvalue(L, -2)
 *         lua.lua_rawset(L, -5)
 *         lua.lua_rawset(L, lua.LUA_REGISTRYINDEX)             # <<<<<<<<<<<<<<
 *         return 0
 * 
 */
  lua_rawset(__pyx_v_L, LUA_REGISTRYINDEX);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":127
 *         lua.lua_rawset(L, -5)
 *         lua.lua_rawset(L, lua.LUA_REGISTRYINDEX)
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int init_python_lib(self) except -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("lupa._lupa.LuaRuntime.register_py_object");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_message);
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_cname);
  __Pyx_DECREF(__pyx_v_pyname);
  __Pyx_DECREF(__pyx_v_obj);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":129
 *         return 0
 * 
 *     cdef int init_python_lib(self) except -1:             # <<<<<<<<<<<<<<
 *         cdef lua_State *L = self._state
 * 
 */

static  int __pyx_f_4lupa_5_lupa_10LuaRuntime_init_python_lib(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *__pyx_v_self) {
  lua_State *__pyx_v_L;
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("init_python_lib");

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":130
 * 
 *     cdef int init_python_lib(self) except -1:
 *         cdef lua_State *L = self._state             # <<<<<<<<<<<<<<
 * 
 *         # create 'python' lib and register our own object metatable
 */
  __pyx_v_L = __pyx_v_self->_state;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":133
 * 
 *         # create 'python' lib and register our own object metatable
 *         lua.luaL_openlib(L, "python", py_lib, 0)             # <<<<<<<<<<<<<<
 *         lua.luaL_newmetatable(L, POBJECT)
 *         lua.luaL_openlib(L, NULL, py_object_lib, 0)
 */
  luaL_openlib(__pyx_v_L, __pyx_k__python, __pyx_v_4lupa_5_lupa_py_lib, 0);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":134
 *         # create 'python' lib and register our own object metatable
 *         lua.luaL_openlib(L, "python", py_lib, 0)
 *         lua.luaL_newmetatable(L, POBJECT)             # <<<<<<<<<<<<<<
 *         lua.luaL_openlib(L, NULL, py_object_lib, 0)
 *         lua.lua_pop(L, 1)
 */
  luaL_newmetatable(__pyx_v_L, __pyx_k__POBJECT);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":135
 *         lua.luaL_openlib(L, "python", py_lib, 0)
 *         lua.luaL_newmetatable(L, POBJECT)
 *         lua.luaL_openlib(L, NULL, py_object_lib, 0)             # <<<<<<<<<<<<<<
 *         lua.lua_pop(L, 1)
 * 
 */
  luaL_openlib(__pyx_v_L, NULL, __pyx_v_4lupa_5_lupa_py_object_lib, 0);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":136
 *         lua.luaL_newmetatable(L, POBJECT)
 *         lua.luaL_openlib(L, NULL, py_object_lib, 0)
 *         lua.lua_pop(L, 1)             # <<<<<<<<<<<<<<
 * 
 *         # register global names in the module
 */
  lua_pop(__pyx_v_L, 1);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":139
 * 
 *         # register global names in the module
 *         self.register_py_object('Py_None', 'none', None)             # <<<<<<<<<<<<<<
 *         self.register_py_object('eval',    'eval', eval)
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime *)__pyx_v_self->__pyx_vtab)->register_py_object(__pyx_v_self, ((PyObject *)__pyx_n_s__Py_None), ((PyObject *)__pyx_n_s__none), Py_None); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":140
 *         # register global names in the module
 *         self.register_py_object('Py_None', 'none', None)
 *         self.register_py_object('eval',    'eval', eval)             # <<<<<<<<<<<<<<
 * 
 *         return 0 # nothing left to return on the stack
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime *)__pyx_v_self->__pyx_vtab)->register_py_object(__pyx_v_self, ((PyObject *)__pyx_n_s__eval), ((PyObject *)__pyx_n_s__eval), __pyx_builtin_eval); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":142
 *         self.register_py_object('eval',    'eval', eval)
 * 
 *         return 0 # nothing left to return on the stack             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("lupa._lupa.LuaRuntime.init_python_lib");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":145
 * 
 * 
 * cdef _LuaObject new_lua_object(LuaRuntime runtime, int n):             # <<<<<<<<<<<<<<
 *     cdef _LuaObject obj = _LuaObject.__new__(_LuaObject)
 *     # additional INCREF to keep runtime from disappearing in GC runs
 */

static  struct __pyx_obj_4lupa_5_lupa__LuaObject *__pyx_f_4lupa_5_lupa_new_lua_object(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *__pyx_v_runtime, int __pyx_v_n) {
  struct __pyx_obj_4lupa_5_lupa__LuaObject *__pyx_v_obj = 0;
  struct __pyx_obj_4lupa_5_lupa__LuaObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("new_lua_object");

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":146
 * 
 * cdef _LuaObject new_lua_object(LuaRuntime runtime, int n):
 *     cdef _LuaObject obj = _LuaObject.__new__(_LuaObject)             # <<<<<<<<<<<<<<
 *     # additional INCREF to keep runtime from disappearing in GC runs
 *     cpython.ref.Py_INCREF(runtime)
 */
  __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_4lupa_5_lupa__LuaObject)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_4lupa_5_lupa__LuaObject))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_obj = ((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":148
 *     cdef _LuaObject obj = _LuaObject.__new__(_LuaObject)
 *     # additional INCREF to keep runtime from disappearing in GC runs
 *     cpython.ref.Py_INCREF(runtime)             # <<<<<<<<<<<<<<
 *     obj._runtime = runtime
 *     obj._ref = lua.luaL_ref(runtime._state, lua.LUA_REGISTRYINDEX)
 */
  Py_INCREF(((PyObject *)__pyx_v_runtime));

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":149
 *     # additional INCREF to keep runtime from disappearing in GC runs
 *     cpython.ref.Py_INCREF(runtime)
 *     obj._runtime = runtime             # <<<<<<<<<<<<<<
 *     obj._ref = lua.luaL_ref(runtime._state, lua.LUA_REGISTRYINDEX)
 *     return obj
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_runtime));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_runtime));
  __Pyx_GOTREF(__pyx_v_obj->_runtime);
  __Pyx_DECREF(((PyObject *)__pyx_v_obj->_runtime));
  __pyx_v_obj->_runtime = __pyx_v_runtime;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":150
 *     cpython.ref.Py_INCREF(runtime)
 *     obj._runtime = runtime
 *     obj._ref = lua.luaL_ref(runtime._state, lua.LUA_REGISTRYINDEX)             # <<<<<<<<<<<<<<
 *     return obj
 * 
 */
  __pyx_v_obj->_ref = luaL_ref(__pyx_v_runtime->_state, LUA_REGISTRYINDEX);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":151
 *     obj._runtime = runtime
 *     obj._ref = lua.luaL_ref(runtime._state, lua.LUA_REGISTRYINDEX)
 *     return obj             # <<<<<<<<<<<<<<
 * 
 * cdef class _LuaObject:
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_obj));
  __pyx_r = __pyx_v_obj;
  goto __pyx_L0;

  __pyx_r = ((struct __pyx_obj_4lupa_5_lupa__LuaObject *)Py_None); __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("lupa._lupa.new_lua_object");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_obj);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":158
 *     cdef int _refiter
 * 
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         raise TypeError("Type cannot be instantiated manually")
 * 
 */

static int __pyx_pf_4lupa_5_lupa_10_LuaObject___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_4lupa_5_lupa_10_LuaObject___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("__init__");
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":159
 * 
 *     def __init__(self):
 *         raise TypeError("Type cannot be instantiated manually")             # <<<<<<<<<<<<<<
 * 
 *     def __cinit__(self):
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_6));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
  __pyx_t_2 = PyObject_Call(__pyx_builtin_TypeError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_Raise(__pyx_t_2, 0, 0);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("lupa._lupa._LuaObject.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":161
 *         raise TypeError("Type cannot be instantiated manually")
 * 
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         self._ref = 0
 *         self._refiter = 0
 */

static int __pyx_pf_4lupa_5_lupa_10_LuaObject___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_4lupa_5_lupa_10_LuaObject___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("__cinit__");
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":162
 * 
 *     def __cinit__(self):
 *         self._ref = 0             # <<<<<<<<<<<<<<
 *         self._refiter = 0
 * 
 */
  ((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_ref = 0;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":163
 *     def __cinit__(self):
 *         self._ref = 0
 *         self._refiter = 0             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  ((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_refiter = 0;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":165
 *         self._refiter = 0
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         if self._runtime is None:
 *             return
 */

static void __pyx_pf_4lupa_5_lupa_10_LuaObject___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pf_4lupa_5_lupa_10_LuaObject___dealloc__(PyObject *__pyx_v_self) {
  lua_State *__pyx_v_L;
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__dealloc__");
  __Pyx_INCREF((PyObject *)__pyx_v_self);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":166
 * 
 *     def __dealloc__(self):
 *         if self._runtime is None:             # <<<<<<<<<<<<<<
 *             return
 *         cdef lua_State* L = self._runtime._state
 */
  __pyx_t_1 = (((PyObject *)((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime) == Py_None);
  if (__pyx_t_1) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":167
 *     def __dealloc__(self):
 *         if self._runtime is None:
 *             return             # <<<<<<<<<<<<<<
 *         cdef lua_State* L = self._runtime._state
 *         lua.luaL_unref(L, lua.LUA_REGISTRYINDEX, self._ref)
 */
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":168
 *         if self._runtime is None:
 *             return
 *         cdef lua_State* L = self._runtime._state             # <<<<<<<<<<<<<<
 *         lua.luaL_unref(L, lua.LUA_REGISTRYINDEX, self._ref)
 *         if self._refiter:
 */
  __pyx_v_L = ((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime->_state;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":169
 *             return
 *         cdef lua_State* L = self._runtime._state
 *         lua.luaL_unref(L, lua.LUA_REGISTRYINDEX, self._ref)             # <<<<<<<<<<<<<<
 *         if self._refiter:
 *             lua.luaL_unref(L, lua.LUA_REGISTRYINDEX, self._refiter)
 */
  luaL_unref(__pyx_v_L, LUA_REGISTRYINDEX, ((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_ref);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":170
 *         cdef lua_State* L = self._runtime._state
 *         lua.luaL_unref(L, lua.LUA_REGISTRYINDEX, self._ref)
 *         if self._refiter:             # <<<<<<<<<<<<<<
 *             lua.luaL_unref(L, lua.LUA_REGISTRYINDEX, self._refiter)
 *         # undo additional INCREF at instantiation time
 */
  if (((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_refiter) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":171
 *         lua.luaL_unref(L, lua.LUA_REGISTRYINDEX, self._ref)
 *         if self._refiter:
 *             lua.luaL_unref(L, lua.LUA_REGISTRYINDEX, self._refiter)             # <<<<<<<<<<<<<<
 *         # undo additional INCREF at instantiation time
 *         cpython.ref.Py_DECREF(self._runtime)
 */
    luaL_unref(__pyx_v_L, LUA_REGISTRYINDEX, ((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_refiter);
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":173
 *             lua.luaL_unref(L, lua.LUA_REGISTRYINDEX, self._refiter)
 *         # undo additional INCREF at instantiation time
 *         cpython.ref.Py_DECREF(self._runtime)             # <<<<<<<<<<<<<<
 * 
 *     def __call__(self, *args):
 */
  Py_DECREF(((PyObject *)((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime));

  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_RefNannyFinishContext();
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":175
 *         cpython.ref.Py_DECREF(self._runtime)
 * 
 *     def __call__(self, *args):             # <<<<<<<<<<<<<<
 *         assert self._runtime is not None
 *         cdef lua_State* L = self._runtime._state
 */

static PyObject *__pyx_pf_4lupa_5_lupa_10_LuaObject___call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_4lupa_5_lupa_10_LuaObject___call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  lua_State *__pyx_v_L;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("__call__");
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__call__", 0))) return NULL;
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __Pyx_INCREF((PyObject *)__pyx_v_self);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":176
 * 
 *     def __call__(self, *args):
 *         assert self._runtime is not None             # <<<<<<<<<<<<<<
 *         cdef lua_State* L = self._runtime._state
 *         self._runtime.lock()
 */
  #ifndef PYREX_WITHOUT_ASSERTIONS
  __pyx_t_1 = (((PyObject *)((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime) != Py_None);
  if (unlikely(!__pyx_t_1)) {
    PyErr_SetNone(PyExc_AssertionError);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":177
 *     def __call__(self, *args):
 *         assert self._runtime is not None
 *         cdef lua_State* L = self._runtime._state             # <<<<<<<<<<<<<<
 *         self._runtime.lock()
 *         try:
 */
  __pyx_v_L = ((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime->_state;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":178
 *         assert self._runtime is not None
 *         cdef lua_State* L = self._runtime._state
 *         self._runtime.lock()             # <<<<<<<<<<<<<<
 *         try:
 *             lua.lua_settop(L, 0)
 */
  __pyx_t_2 = ((struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime *)((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime->__pyx_vtab)->lock(((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":179
 *         cdef lua_State* L = self._runtime._state
 *         self._runtime.lock()
 *         try:             # <<<<<<<<<<<<<<
 *             lua.lua_settop(L, 0)
 *             lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, self._ref)
 */
  /*try:*/ {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":180
 *         self._runtime.lock()
 *         try:
 *             lua.lua_settop(L, 0)             # <<<<<<<<<<<<<<
 *             lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, self._ref)
 *             return call_lua(self._runtime, args)
 */
    lua_settop(__pyx_v_L, 0);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":181
 *         try:
 *             lua.lua_settop(L, 0)
 *             lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, self._ref)             # <<<<<<<<<<<<<<
 *             return call_lua(self._runtime, args)
 *         finally:
 */
    lua_rawgeti(__pyx_v_L, LUA_REGISTRYINDEX, ((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_ref);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":182
 *             lua.lua_settop(L, 0)
 *             lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, self._ref)
 *             return call_lua(self._runtime, args)             # <<<<<<<<<<<<<<
 *         finally:
 *             self._runtime.unlock()
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __pyx_f_4lupa_5_lupa_call_lua(((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime, __pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L6;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L5;
  }
  /*finally:*/ {
    int __pyx_why;
    PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb;
    int __pyx_exc_lineno;
    __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
    __pyx_why = 0; goto __pyx_L7;
    __pyx_L5: __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
    __pyx_why = 3; goto __pyx_L7;
    __pyx_L6: {
      __pyx_why = 4;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb);
      __pyx_exc_lineno = __pyx_lineno;
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":184
 *             return call_lua(self._runtime, args)
 *         finally:
 *             self._runtime.unlock()             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
    ((struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime *)((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime->__pyx_vtab)->unlock(((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime);
    switch (__pyx_why) {
      case 3: goto __pyx_L0;
      case 4: {
        __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb);
        __pyx_lineno = __pyx_exc_lineno;
        __pyx_exc_type = 0;
        __pyx_exc_value = 0;
        __pyx_exc_tb = 0;
        goto __pyx_L1_error;
      }
    }
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("lupa._lupa._LuaObject.__call__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":186
 *             self._runtime.unlock()
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         assert self._runtime is not None
 *         cdef lua_State* L = self._runtime._state
 */

static PyObject *__pyx_pf_4lupa_5_lupa_10_LuaObject___str__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_4lupa_5_lupa_10_LuaObject___str__(PyObject *__pyx_v_self) {
  lua_State *__pyx_v_L;
  PyObject *__pyx_v_py_string = 0;
  PyObject *__pyx_v_py_bytes = 0;
  char *__pyx_v_s;
  void *__pyx_v_ptr;
  int __pyx_v_lua_type;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  __Pyx_RefNannySetupContext("__str__");
  __Pyx_INCREF((PyObject *)__pyx_v_self);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":187
 * 
 *     def __str__(self):
 *         assert self._runtime is not None             # <<<<<<<<<<<<<<
 *         cdef lua_State* L = self._runtime._state
 *         cdef unicode py_string = None
 */
  #ifndef PYREX_WITHOUT_ASSERTIONS
  __pyx_t_1 = (((PyObject *)((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime) != Py_None);
  if (unlikely(!__pyx_t_1)) {
    PyErr_SetNone(PyExc_AssertionError);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":188
 *     def __str__(self):
 *         assert self._runtime is not None
 *         cdef lua_State* L = self._runtime._state             # <<<<<<<<<<<<<<
 *         cdef unicode py_string = None
 *         cdef bytes py_bytes = None
 */
  __pyx_v_L = ((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime->_state;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":189
 *         assert self._runtime is not None
 *         cdef lua_State* L = self._runtime._state
 *         cdef unicode py_string = None             # <<<<<<<<<<<<<<
 *         cdef bytes py_bytes = None
 *         cdef char* s
 */
  __Pyx_INCREF(Py_None);
  __pyx_v_py_string = ((PyObject *)Py_None);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":190
 *         cdef lua_State* L = self._runtime._state
 *         cdef unicode py_string = None
 *         cdef bytes py_bytes = None             # <<<<<<<<<<<<<<
 *         cdef char* s
 *         cdef void* ptr
 */
  __Pyx_INCREF(Py_None);
  __pyx_v_py_bytes = ((PyObject *)Py_None);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":194
 *         cdef void* ptr
 *         cdef int lua_type
 *         self._runtime.lock()             # <<<<<<<<<<<<<<
 *         try:
 *             lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, self._ref)
 */
  __pyx_t_2 = ((struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime *)((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime->__pyx_vtab)->lock(((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":195
 *         cdef int lua_type
 *         self._runtime.lock()
 *         try:             # <<<<<<<<<<<<<<
 *             lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, self._ref)
 *             if lua.luaL_callmeta(L, -1, "__tostring"):
 */
  /*try:*/ {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":196
 *         self._runtime.lock()
 *         try:
 *             lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, self._ref)             # <<<<<<<<<<<<<<
 *             if lua.luaL_callmeta(L, -1, "__tostring"):
 *                 s = lua.lua_tostring(L, -1)
 */
    lua_rawgeti(__pyx_v_L, LUA_REGISTRYINDEX, ((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_ref);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":197
 *         try:
 *             lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, self._ref)
 *             if lua.luaL_callmeta(L, -1, "__tostring"):             # <<<<<<<<<<<<<<
 *                 s = lua.lua_tostring(L, -1)
 *                 lua.lua_pop(L, 1)
 */
    __pyx_t_2 = luaL_callmeta(__pyx_v_L, -1, __pyx_k____tostring);
    if (__pyx_t_2) {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":198
 *             lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, self._ref)
 *             if lua.luaL_callmeta(L, -1, "__tostring"):
 *                 s = lua.lua_tostring(L, -1)             # <<<<<<<<<<<<<<
 *                 lua.lua_pop(L, 1)
 *                 if s:
 */
      __pyx_v_s = lua_tostring(__pyx_v_L, -1);

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":199
 *             if lua.luaL_callmeta(L, -1, "__tostring"):
 *                 s = lua.lua_tostring(L, -1)
 *                 lua.lua_pop(L, 1)             # <<<<<<<<<<<<<<
 *                 if s:
 *                     try:
 */
      lua_pop(__pyx_v_L, 1);

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":200
 *                 s = lua.lua_tostring(L, -1)
 *                 lua.lua_pop(L, 1)
 *                 if s:             # <<<<<<<<<<<<<<
 *                     try:
 *                         py_string = s.decode('UTF-8')
 */
      __pyx_t_1 = (__pyx_v_s != 0);
      if (__pyx_t_1) {

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":201
 *                 lua.lua_pop(L, 1)
 *                 if s:
 *                     try:             # <<<<<<<<<<<<<<
 *                         py_string = s.decode('UTF-8')
 *                     except UnicodeDecodeError:
 */
        {
          PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
          __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
          __Pyx_XGOTREF(__pyx_save_exc_type);
          __Pyx_XGOTREF(__pyx_save_exc_value);
          __Pyx_XGOTREF(__pyx_save_exc_tb);
          /*try:*/ {

            /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":202
 *                 if s:
 *                     try:
 *                         py_string = s.decode('UTF-8')             # <<<<<<<<<<<<<<
 *                     except UnicodeDecodeError:
 *                         # safe 'decode'
 */
            __pyx_t_3 = ((PyObject *)PyUnicode_DecodeUTF8(__pyx_v_s, strlen(__pyx_v_s), NULL)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
            __Pyx_GOTREF(((PyObject *)__pyx_t_3));
            if (!(likely(PyUnicode_CheckExact(((PyObject *)__pyx_t_3)))||((((PyObject *)__pyx_t_3)) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected unicode, got %.200s", Py_TYPE(((PyObject *)__pyx_t_3))->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
            __Pyx_DECREF(((PyObject *)__pyx_v_py_string));
            __pyx_v_py_string = ((PyObject *)__pyx_t_3);
            __pyx_t_3 = 0;
          }
          __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
          __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
          __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
          goto __pyx_L17_try_end;
          __pyx_L10_error:;
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;

          /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":203
 *                     try:
 *                         py_string = s.decode('UTF-8')
 *                     except UnicodeDecodeError:             # <<<<<<<<<<<<<<
 *                         # safe 'decode'
 *                         py_string = s.decode('ISO-8859-1')
 */
          __pyx_t_2 = PyErr_ExceptionMatches(__pyx_builtin_UnicodeDecodeError);
          if (__pyx_t_2) {
            __Pyx_AddTraceback("lupa._lupa._LuaObject.__str__");
            if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_GOTREF(__pyx_t_5);

            /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":205
 *                     except UnicodeDecodeError:
 *                         # safe 'decode'
 *                         py_string = s.decode('ISO-8859-1')             # <<<<<<<<<<<<<<
 *             if py_string is None:
 *                 lua_type = lua.lua_type(L, -1)
 */
            __pyx_t_6 = ((PyObject *)PyUnicode_DecodeLatin1(__pyx_v_s, strlen(__pyx_v_s), NULL)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
            __Pyx_GOTREF(((PyObject *)__pyx_t_6));
            if (!(likely(PyUnicode_CheckExact(((PyObject *)__pyx_t_6)))||((((PyObject *)__pyx_t_6)) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected unicode, got %.200s", Py_TYPE(((PyObject *)__pyx_t_6))->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
            __Pyx_DECREF(((PyObject *)__pyx_v_py_string));
            __pyx_v_py_string = ((PyObject *)__pyx_t_6);
            __pyx_t_6 = 0;
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            goto __pyx_L11_exception_handled;
          }
          __pyx_L12_except_error:;
          __Pyx_XGIVEREF(__pyx_save_exc_type);
          __Pyx_XGIVEREF(__pyx_save_exc_value);
          __Pyx_XGIVEREF(__pyx_save_exc_tb);
          __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
          goto __pyx_L6;
          __pyx_L11_exception_handled:;
          __Pyx_XGIVEREF(__pyx_save_exc_type);
          __Pyx_XGIVEREF(__pyx_save_exc_value);
          __Pyx_XGIVEREF(__pyx_save_exc_tb);
          __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
          __pyx_L17_try_end:;
        }
        goto __pyx_L9;
      }
      __pyx_L9:;
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":206
 *                         # safe 'decode'
 *                         py_string = s.decode('ISO-8859-1')
 *             if py_string is None:             # <<<<<<<<<<<<<<
 *                 lua_type = lua.lua_type(L, -1)
 *                 ptr = NULL
 */
    __pyx_t_1 = (__pyx_v_py_string == ((PyObject *)Py_None));
    if (__pyx_t_1) {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":207
 *                         py_string = s.decode('ISO-8859-1')
 *             if py_string is None:
 *                 lua_type = lua.lua_type(L, -1)             # <<<<<<<<<<<<<<
 *                 ptr = NULL
 *                 if lua_type in (lua.LUA_TTABLE, lua.LUA_TFUNCTION):
 */
      __pyx_v_lua_type = lua_type(__pyx_v_L, -1);

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":208
 *             if py_string is None:
 *                 lua_type = lua.lua_type(L, -1)
 *                 ptr = NULL             # <<<<<<<<<<<<<<
 *                 if lua_type in (lua.LUA_TTABLE, lua.LUA_TFUNCTION):
 *                     ptr = <void*>lua.lua_topointer(L, -1)
 */
      __pyx_v_ptr = NULL;

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":209
 *                 lua_type = lua.lua_type(L, -1)
 *                 ptr = NULL
 *                 if lua_type in (lua.LUA_TTABLE, lua.LUA_TFUNCTION):             # <<<<<<<<<<<<<<
 *                     ptr = <void*>lua.lua_topointer(L, -1)
 *                 elif lua_type in (lua.LUA_TUSERDATA, lua.LUA_TLIGHTUSERDATA):
 */
      switch (__pyx_v_lua_type) {
        case LUA_TTABLE:
        case LUA_TFUNCTION:

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":210
 *                 ptr = NULL
 *                 if lua_type in (lua.LUA_TTABLE, lua.LUA_TFUNCTION):
 *                     ptr = <void*>lua.lua_topointer(L, -1)             # <<<<<<<<<<<<<<
 *                 elif lua_type in (lua.LUA_TUSERDATA, lua.LUA_TLIGHTUSERDATA):
 *                     ptr = <void*>lua.lua_touserdata(L, -1)
 */
        __pyx_v_ptr = ((void *)lua_topointer(__pyx_v_L, -1));
        break;

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":211
 *                 if lua_type in (lua.LUA_TTABLE, lua.LUA_TFUNCTION):
 *                     ptr = <void*>lua.lua_topointer(L, -1)
 *                 elif lua_type in (lua.LUA_TUSERDATA, lua.LUA_TLIGHTUSERDATA):             # <<<<<<<<<<<<<<
 *                     ptr = <void*>lua.lua_touserdata(L, -1)
 *                 elif lua_type == lua.LUA_TTHREAD:
 */
        case LUA_TUSERDATA:
        case LUA_TLIGHTUSERDATA:

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":212
 *                     ptr = <void*>lua.lua_topointer(L, -1)
 *                 elif lua_type in (lua.LUA_TUSERDATA, lua.LUA_TLIGHTUSERDATA):
 *                     ptr = <void*>lua.lua_touserdata(L, -1)             # <<<<<<<<<<<<<<
 *                 elif lua_type == lua.LUA_TTHREAD:
 *                     ptr = <void*>lua.lua_tothread(L, -1)
 */
        __pyx_v_ptr = ((void *)lua_touserdata(__pyx_v_L, -1));
        break;

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":213
 *                 elif lua_type in (lua.LUA_TUSERDATA, lua.LUA_TLIGHTUSERDATA):
 *                     ptr = <void*>lua.lua_touserdata(L, -1)
 *                 elif lua_type == lua.LUA_TTHREAD:             # <<<<<<<<<<<<<<
 *                     ptr = <void*>lua.lua_tothread(L, -1)
 *                 if ptr is not NULL:
 */
        case LUA_TTHREAD:

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":214
 *                     ptr = <void*>lua.lua_touserdata(L, -1)
 *                 elif lua_type == lua.LUA_TTHREAD:
 *                     ptr = <void*>lua.lua_tothread(L, -1)             # <<<<<<<<<<<<<<
 *                 if ptr is not NULL:
 *                     py_bytes = cpython.bytes.PyBytes_FromFormat(
 */
        __pyx_v_ptr = ((void *)lua_tothread(__pyx_v_L, -1));
        break;
      }

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":215
 *                 elif lua_type == lua.LUA_TTHREAD:
 *                     ptr = <void*>lua.lua_tothread(L, -1)
 *                 if ptr is not NULL:             # <<<<<<<<<<<<<<
 *                     py_bytes = cpython.bytes.PyBytes_FromFormat(
 *                         "<Lua %s at %p>", lua.lua_typename(L, lua_type), ptr)
 */
      __pyx_t_1 = (__pyx_v_ptr != NULL);
      if (__pyx_t_1) {

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":217
 *                 if ptr is not NULL:
 *                     py_bytes = cpython.bytes.PyBytes_FromFormat(
 *                         "<Lua %s at %p>", lua.lua_typename(L, lua_type), ptr)             # <<<<<<<<<<<<<<
 *                 else:
 *                     py_bytes = cpython.bytes.PyBytes_FromFormat(
 */
        __pyx_t_5 = PyBytes_FromFormat(__pyx_k_7, lua_typename(__pyx_v_L, __pyx_v_lua_type), __pyx_v_ptr); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L6;}
        __Pyx_GOTREF(__pyx_t_5);
        if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L6;}
        __Pyx_DECREF(((PyObject *)__pyx_v_py_bytes));
        __pyx_v_py_bytes = ((PyObject *)__pyx_t_5);
        __pyx_t_5 = 0;
        goto __pyx_L21;
      }
      /*else*/ {

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":220
 *                 else:
 *                     py_bytes = cpython.bytes.PyBytes_FromFormat(
 *                         "<Lua %s>", lua.lua_typename(L, lua_type))             # <<<<<<<<<<<<<<
 *                 try:
 *                     py_string = py_bytes.decode('UTF-8')
 */
        __pyx_t_5 = PyBytes_FromFormat(__pyx_k_8, lua_typename(__pyx_v_L, __pyx_v_lua_type)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L6;}
        __Pyx_GOTREF(__pyx_t_5);
        if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L6;}
        __Pyx_DECREF(((PyObject *)__pyx_v_py_bytes));
        __pyx_v_py_bytes = ((PyObject *)__pyx_t_5);
        __pyx_t_5 = 0;
      }
      __pyx_L21:;

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":221
 *                     py_bytes = cpython.bytes.PyBytes_FromFormat(
 *                         "<Lua %s>", lua.lua_typename(L, lua_type))
 *                 try:             # <<<<<<<<<<<<<<
 *                     py_string = py_bytes.decode('UTF-8')
 *                 except UnicodeDecodeError:
 */
      {
        PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
        __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
        __Pyx_XGOTREF(__pyx_save_exc_type);
        __Pyx_XGOTREF(__pyx_save_exc_value);
        __Pyx_XGOTREF(__pyx_save_exc_tb);
        /*try:*/ {

          /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":222
 *                         "<Lua %s>", lua.lua_typename(L, lua_type))
 *                 try:
 *                     py_string = py_bytes.decode('UTF-8')             # <<<<<<<<<<<<<<
 *                 except UnicodeDecodeError:
 *                     # safe 'decode'
 */
          __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_py_bytes), __pyx_n_s__decode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
          PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_s_9));
          __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
          __pyx_t_3 = PyObject_Call(__pyx_t_5, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          if (!(likely(PyUnicode_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected unicode, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
          __Pyx_DECREF(((PyObject *)__pyx_v_py_string));
          __pyx_v_py_string = ((PyObject *)__pyx_t_3);
          __pyx_t_3 = 0;
        }
        __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
        __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
        __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
        goto __pyx_L29_try_end;
        __pyx_L22_error:;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":223
 *                 try:
 *                     py_string = py_bytes.decode('UTF-8')
 *                 except UnicodeDecodeError:             # <<<<<<<<<<<<<<
 *                     # safe 'decode'
 *                     py_string = py_bytes.decode('ISO-8859-1')
 */
        __pyx_t_2 = PyErr_ExceptionMatches(__pyx_builtin_UnicodeDecodeError);
        if (__pyx_t_2) {
          __Pyx_AddTraceback("lupa._lupa._LuaObject.__str__");
          if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_GOTREF(__pyx_t_5);

          /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":225
 *                 except UnicodeDecodeError:
 *                     # safe 'decode'
 *                     py_string = py_bytes.decode('ISO-8859-1')             # <<<<<<<<<<<<<<
 *         finally:
 *             self._runtime.unlock()
 */
          __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_py_bytes), __pyx_n_s__decode); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
          PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_kp_s_10));
          __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
          __pyx_t_8 = PyObject_Call(__pyx_t_6, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (!(likely(PyUnicode_CheckExact(__pyx_t_8))||((__pyx_t_8) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected unicode, got %.200s", Py_TYPE(__pyx_t_8)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
          __Pyx_DECREF(((PyObject *)__pyx_v_py_string));
          __pyx_v_py_string = ((PyObject *)__pyx_t_8);
          __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          goto __pyx_L23_exception_handled;
        }
        __pyx_L24_except_error:;
        __Pyx_XGIVEREF(__pyx_save_exc_type);
        __Pyx_XGIVEREF(__pyx_save_exc_value);
        __Pyx_XGIVEREF(__pyx_save_exc_tb);
        __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
        goto __pyx_L6;
        __pyx_L23_exception_handled:;
        __Pyx_XGIVEREF(__pyx_save_exc_type);
        __Pyx_XGIVEREF(__pyx_save_exc_value);
        __Pyx_XGIVEREF(__pyx_save_exc_tb);
        __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
        __pyx_L29_try_end:;
      }
      goto __pyx_L20;
    }
    __pyx_L20:;
  }
  /*finally:*/ {
    int __pyx_why;
    PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb;
    int __pyx_exc_lineno;
    __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
    __pyx_why = 0; goto __pyx_L7;
    __pyx_L6: {
      __pyx_why = 4;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb);
      __pyx_exc_lineno = __pyx_lineno;
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":227
 *                     py_string = py_bytes.decode('ISO-8859-1')
 *         finally:
 *             self._runtime.unlock()             # <<<<<<<<<<<<<<
 *         return py_string
 * 
 */
    ((struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime *)((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime->__pyx_vtab)->unlock(((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime);
    switch (__pyx_why) {
      case 4: {
        __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb);
        __pyx_lineno = __pyx_exc_lineno;
        __pyx_exc_type = 0;
        __pyx_exc_value = 0;
        __pyx_exc_tb = 0;
        goto __pyx_L1_error;
      }
    }
  }

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":228
 *         finally:
 *             self._runtime.unlock()
 *         return py_string             # <<<<<<<<<<<<<<
 * 
 *     def __getattr__(self, name):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_py_string));
  __pyx_r = ((PyObject *)__pyx_v_py_string);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("lupa._lupa._LuaObject.__str__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_py_string);
  __Pyx_XDECREF(__pyx_v_py_bytes);
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":230
 *         return py_string
 * 
 *     def __getattr__(self, name):             # <<<<<<<<<<<<<<
 *         assert self._runtime is not None
 *         cdef lua_State* L = self._runtime._state
 */

static PyObject *__pyx_pf_4lupa_5_lupa_10_LuaObject___getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_name); /*proto*/
static PyObject *__pyx_pf_4lupa_5_lupa_10_LuaObject___getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_name) {
  lua_State *__pyx_v_L;
  PyObject *__pyx_v_name_utf = 0;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  __Pyx_RefNannySetupContext("__getattr__");
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_name);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":231
 * 
 *     def __getattr__(self, name):
 *         assert self._runtime is not None             # <<<<<<<<<<<<<<
 *         cdef lua_State* L = self._runtime._state
 *         cdef bytes name_utf = name if isinstance(name, bytes) else name.encode('UTF-8')
 */
  #ifndef PYREX_WITHOUT_ASSERTIONS
  __pyx_t_1 = (((PyObject *)((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime) != Py_None);
  if (unlikely(!__pyx_t_1)) {
    PyErr_SetNone(PyExc_AssertionError);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":232
 *     def __getattr__(self, name):
 *         assert self._runtime is not None
 *         cdef lua_State* L = self._runtime._state             # <<<<<<<<<<<<<<
 *         cdef bytes name_utf = name if isinstance(name, bytes) else name.encode('UTF-8')
 *         self._runtime.lock()
 */
  __pyx_v_L = ((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime->_state;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":233
 *         assert self._runtime is not None
 *         cdef lua_State* L = self._runtime._state
 *         cdef bytes name_utf = name if isinstance(name, bytes) else name.encode('UTF-8')             # <<<<<<<<<<<<<<
 *         self._runtime.lock()
 *         try:
 */
  __pyx_t_1 = PyObject_TypeCheck(__pyx_v_name, ((PyTypeObject *)((PyObject*)&PyBytes_Type))); 
  if (__pyx_t_1) {
    __Pyx_INCREF(__pyx_v_name);
    __pyx_t_2 = __pyx_v_name;
  } else {
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_name, __pyx_n_s__encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
    PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_s_9));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
    __pyx_t_5 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_2 = __pyx_t_5;
    __pyx_t_5 = 0;
  }
  if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_name_utf = ((PyObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":234
 *         cdef lua_State* L = self._runtime._state
 *         cdef bytes name_utf = name if isinstance(name, bytes) else name.encode('UTF-8')
 *         self._runtime.lock()             # <<<<<<<<<<<<<<
 *         try:
 *             lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, self._ref)
 */
  __pyx_t_6 = ((struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime *)((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime->__pyx_vtab)->lock(((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":235
 *         cdef bytes name_utf = name if isinstance(name, bytes) else name.encode('UTF-8')
 *         self._runtime.lock()
 *         try:             # <<<<<<<<<<<<<<
 *             lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, self._ref)
 *             if lua.lua_isnil(L, -1):
 */
  /*try:*/ {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":236
 *         self._runtime.lock()
 *         try:
 *             lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, self._ref)             # <<<<<<<<<<<<<<
 *             if lua.lua_isnil(L, -1):
 *                 lua.lua_pop(L, 1)
 */
    lua_rawgeti(__pyx_v_L, LUA_REGISTRYINDEX, ((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_ref);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":237
 *         try:
 *             lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, self._ref)
 *             if lua.lua_isnil(L, -1):             # <<<<<<<<<<<<<<
 *                 lua.lua_pop(L, 1)
 *                 raise LuaError("lost reference")
 */
    __pyx_t_1 = lua_isnil(__pyx_v_L, -1);
    if (__pyx_t_1) {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":238
 *             lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, self._ref)
 *             if lua.lua_isnil(L, -1):
 *                 lua.lua_pop(L, 1)             # <<<<<<<<<<<<<<
 *                 raise LuaError("lost reference")
 *             py_to_lua(self._runtime, name_utf, 0)
 */
      lua_pop(__pyx_v_L, 1);

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":239
 *             if lua.lua_isnil(L, -1):
 *                 lua.lua_pop(L, 1)
 *                 raise LuaError("lost reference")             # <<<<<<<<<<<<<<
 *             py_to_lua(self._runtime, name_utf, 0)
 *             lua.lua_gettable(L, -2)
 */
      __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__LuaError); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L6;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L6;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(((PyObject *)__pyx_kp_s_11));
      PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_11));
      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_11));
      __pyx_t_4 = PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L6;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_Raise(__pyx_t_4, 0, 0);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L6;}
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":240
 *                 lua.lua_pop(L, 1)
 *                 raise LuaError("lost reference")
 *             py_to_lua(self._runtime, name_utf, 0)             # <<<<<<<<<<<<<<
 *             lua.lua_gettable(L, -2)
 *             try:
 */
    __pyx_t_1 = __pyx_f_4lupa_5_lupa_py_to_lua(((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime, ((PyObject *)__pyx_v_name_utf), 0); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 240; __pyx_clineno = __LINE__; goto __pyx_L6;}

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":241
 *                 raise LuaError("lost reference")
 *             py_to_lua(self._runtime, name_utf, 0)
 *             lua.lua_gettable(L, -2)             # <<<<<<<<<<<<<<
 *             try:
 *                 return py_from_lua(self._runtime, -1)
 */
    lua_gettable(__pyx_v_L, -2);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":242
 *             py_to_lua(self._runtime, name_utf, 0)
 *             lua.lua_gettable(L, -2)
 *             try:             # <<<<<<<<<<<<<<
 *                 return py_from_lua(self._runtime, -1)
 *             finally:
 */
    /*try:*/ {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":243
 *             lua.lua_gettable(L, -2)
 *             try:
 *                 return py_from_lua(self._runtime, -1)             # <<<<<<<<<<<<<<
 *             finally:
 *                 lua.lua_settop(L, 0)
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_4 = __pyx_f_4lupa_5_lupa_py_from_lua(((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime, -1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L10;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_r = __pyx_t_4;
      __pyx_t_4 = 0;
      goto __pyx_L9;
    }
    /*finally:*/ {
      int __pyx_why;
      PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb;
      int __pyx_exc_lineno;
      __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
      __pyx_why = 0; goto __pyx_L11;
      __pyx_L9: __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
      __pyx_why = 3; goto __pyx_L11;
      __pyx_L10: {
        __pyx_why = 4;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb);
        __pyx_exc_lineno = __pyx_lineno;
        goto __pyx_L11;
      }
      __pyx_L11:;

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":245
 *                 return py_from_lua(self._runtime, -1)
 *             finally:
 *                 lua.lua_settop(L, 0)             # <<<<<<<<<<<<<<
 *         finally:
 *             self._runtime.unlock()
 */
      lua_settop(__pyx_v_L, 0);
      switch (__pyx_why) {
        case 3: goto __pyx_L5;
        case 4: {
          __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb);
          __pyx_lineno = __pyx_exc_lineno;
          __pyx_exc_type = 0;
          __pyx_exc_value = 0;
          __pyx_exc_tb = 0;
          goto __pyx_L6;
        }
      }
    }
  }
  /*finally:*/ {
    int __pyx_why;
    PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb;
    int __pyx_exc_lineno;
    __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
    __pyx_why = 0; goto __pyx_L7;
    __pyx_L5: __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
    __pyx_why = 3; goto __pyx_L7;
    __pyx_L6: {
      __pyx_why = 4;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb);
      __pyx_exc_lineno = __pyx_lineno;
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":247
 *                 lua.lua_settop(L, 0)
 *         finally:
 *             self._runtime.unlock()             # <<<<<<<<<<<<<<
 * 
 * 
 */
    ((struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime *)((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime->__pyx_vtab)->unlock(((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_self)->_runtime);
    switch (__pyx_why) {
      case 3: goto __pyx_L0;
      case 4: {
        __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb);
        __pyx_lineno = __pyx_exc_lineno;
        __pyx_exc_type = 0;
        __pyx_exc_value = 0;
        __pyx_exc_tb = 0;
        goto __pyx_L1_error;
      }
    }
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("lupa._lupa._LuaObject.__getattr__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_name_utf);
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_name);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":250
 * 
 * 
 * cdef int py_asfunc_call(lua_State *L):             # <<<<<<<<<<<<<<
 *     lua.lua_pushvalue(L, lua.lua_upvalueindex(1))
 *     lua.lua_insert(L, 1)
 */

static  int __pyx_f_4lupa_5_lupa_py_asfunc_call(lua_State *__pyx_v_L) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("py_asfunc_call");

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":251
 * 
 * cdef int py_asfunc_call(lua_State *L):
 *     lua.lua_pushvalue(L, lua.lua_upvalueindex(1))             # <<<<<<<<<<<<<<
 *     lua.lua_insert(L, 1)
 *     return py_object_call(L)
 */
  lua_pushvalue(__pyx_v_L, lua_upvalueindex(1));

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":252
 * cdef int py_asfunc_call(lua_State *L):
 *     lua.lua_pushvalue(L, lua.lua_upvalueindex(1))
 *     lua.lua_insert(L, 1)             # <<<<<<<<<<<<<<
 *     return py_object_call(L)
 * 
 */
  lua_insert(__pyx_v_L, 1);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":253
 *     lua.lua_pushvalue(L, lua.lua_upvalueindex(1))
 *     lua.lua_insert(L, 1)
 *     return py_object_call(L)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_f_4lupa_5_lupa_py_object_call(__pyx_v_L);
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":256
 * 
 * 
 * cdef object py_from_lua(LuaRuntime runtime, int n):             # <<<<<<<<<<<<<<
 *     cdef lua_State *L = runtime._state
 *     cdef size_t size
 */

static  PyObject *__pyx_f_4lupa_5_lupa_py_from_lua(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *__pyx_v_runtime, int __pyx_v_n) {
  lua_State *__pyx_v_L;
  size_t __pyx_v_size;
  char *__pyx_v_s;
  lua_Number __pyx_v_number;
  struct __pyx_t_4lupa_5_lupa_py_object *__pyx_v_py_obj;
  int __pyx_v_lua_type;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("py_from_lua");
  __Pyx_INCREF((PyObject *)__pyx_v_runtime);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":257
 * 
 * cdef object py_from_lua(LuaRuntime runtime, int n):
 *     cdef lua_State *L = runtime._state             # <<<<<<<<<<<<<<
 *     cdef size_t size
 *     cdef char* s
 */
  __pyx_v_L = __pyx_v_runtime->_state;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":262
 *     cdef lua.lua_Number number
 *     cdef py_object* py_obj
 *     cdef int lua_type = lua.lua_type(L, n)             # <<<<<<<<<<<<<<
 * 
 *     if lua_type == lua.LUA_TNIL:
 */
  __pyx_v_lua_type = lua_type(__pyx_v_L, __pyx_v_n);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":264
 *     cdef int lua_type = lua.lua_type(L, n)
 * 
 *     if lua_type == lua.LUA_TNIL:             # <<<<<<<<<<<<<<
 *         return None
 *     elif lua_type == lua.LUA_TSTRING:
 */
  switch (__pyx_v_lua_type) {
    case LUA_TNIL:

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":265
 * 
 *     if lua_type == lua.LUA_TNIL:
 *         return None             # <<<<<<<<<<<<<<
 *     elif lua_type == lua.LUA_TSTRING:
 *         s = lua.lua_tolstring(L, n, &size)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    break;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":266
 *     if lua_type == lua.LUA_TNIL:
 *         return None
 *     elif lua_type == lua.LUA_TSTRING:             # <<<<<<<<<<<<<<
 *         s = lua.lua_tolstring(L, n, &size)
 *         return s[:size]
 */
    case LUA_TSTRING:

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":267
 *         return None
 *     elif lua_type == lua.LUA_TSTRING:
 *         s = lua.lua_tolstring(L, n, &size)             # <<<<<<<<<<<<<<
 *         return s[:size]
 *     elif lua_type == lua.LUA_TNUMBER:
 */
    __pyx_v_s = lua_tolstring(__pyx_v_L, __pyx_v_n, (&__pyx_v_size));

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":268
 *     elif lua_type == lua.LUA_TSTRING:
 *         s = lua.lua_tolstring(L, n, &size)
 *         return s[:size]             # <<<<<<<<<<<<<<
 *     elif lua_type == lua.LUA_TNUMBER:
 *         number = lua.lua_tonumber(L, n)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyBytes_FromStringAndSize(__pyx_v_s + 0, __pyx_v_size - 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    __pyx_r = ((PyObject *)__pyx_t_1);
    __pyx_t_1 = 0;
    goto __pyx_L0;
    break;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":269
 *         s = lua.lua_tolstring(L, n, &size)
 *         return s[:size]
 *     elif lua_type == lua.LUA_TNUMBER:             # <<<<<<<<<<<<<<
 *         number = lua.lua_tonumber(L, n)
 *         if number != <long>number:
 */
    case LUA_TNUMBER:

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":270
 *         return s[:size]
 *     elif lua_type == lua.LUA_TNUMBER:
 *         number = lua.lua_tonumber(L, n)             # <<<<<<<<<<<<<<
 *         if number != <long>number:
 *             return <double>number
 */
    __pyx_v_number = lua_tonumber(__pyx_v_L, __pyx_v_n);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":271
 *     elif lua_type == lua.LUA_TNUMBER:
 *         number = lua.lua_tonumber(L, n)
 *         if number != <long>number:             # <<<<<<<<<<<<<<
 *             return <double>number
 *         else:
 */
    __pyx_t_2 = (__pyx_v_number != ((long)__pyx_v_number));
    if (__pyx_t_2) {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":272
 *         number = lua.lua_tonumber(L, n)
 *         if number != <long>number:
 *             return <double>number             # <<<<<<<<<<<<<<
 *         else:
 *             return <long>number
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = PyFloat_FromDouble(((double)__pyx_v_number)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;
      goto __pyx_L3;
    }
    /*else*/ {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":274
 *             return <double>number
 *         else:
 *             return <long>number             # <<<<<<<<<<<<<<
 *     elif lua_type == lua.LUA_TBOOLEAN:
 *         return lua.lua_toboolean(L, n)
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = PyInt_FromLong(((long)__pyx_v_number)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __pyx_L3:;
    break;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":275
 *         else:
 *             return <long>number
 *     elif lua_type == lua.LUA_TBOOLEAN:             # <<<<<<<<<<<<<<
 *         return lua.lua_toboolean(L, n)
 *     elif lua_type == lua.LUA_TUSERDATA:
 */
    case LUA_TBOOLEAN:

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":276
 *             return <long>number
 *     elif lua_type == lua.LUA_TBOOLEAN:
 *         return lua.lua_toboolean(L, n)             # <<<<<<<<<<<<<<
 *     elif lua_type == lua.LUA_TUSERDATA:
 *         py_obj = <py_object*>lua.luaL_checkudata(L, n, POBJECT)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyBool_FromLong(lua_toboolean(__pyx_v_L, __pyx_v_n)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
    break;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":277
 *     elif lua_type == lua.LUA_TBOOLEAN:
 *         return lua.lua_toboolean(L, n)
 *     elif lua_type == lua.LUA_TUSERDATA:             # <<<<<<<<<<<<<<
 *         py_obj = <py_object*>lua.luaL_checkudata(L, n, POBJECT)
 *         if py_obj:
 */
    case LUA_TUSERDATA:

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":278
 *         return lua.lua_toboolean(L, n)
 *     elif lua_type == lua.LUA_TUSERDATA:
 *         py_obj = <py_object*>lua.luaL_checkudata(L, n, POBJECT)             # <<<<<<<<<<<<<<
 *         if py_obj:
 *             return <object>py_obj.obj
 */
    __pyx_v_py_obj = ((struct __pyx_t_4lupa_5_lupa_py_object *)luaL_checkudata(__pyx_v_L, __pyx_v_n, __pyx_k__POBJECT));

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":279
 *     elif lua_type == lua.LUA_TUSERDATA:
 *         py_obj = <py_object*>lua.luaL_checkudata(L, n, POBJECT)
 *         if py_obj:             # <<<<<<<<<<<<<<
 *             return <object>py_obj.obj
 *     return new_lua_object(runtime, n)
 */
    __pyx_t_2 = (__pyx_v_py_obj != 0);
    if (__pyx_t_2) {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":280
 *         py_obj = <py_object*>lua.luaL_checkudata(L, n, POBJECT)
 *         if py_obj:
 *             return <object>py_obj.obj             # <<<<<<<<<<<<<<
 *     return new_lua_object(runtime, n)
 * 
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(((PyObject *)__pyx_v_py_obj->obj));
      __pyx_r = ((PyObject *)__pyx_v_py_obj->obj);
      goto __pyx_L0;
      goto __pyx_L4;
    }
    __pyx_L4:;
    break;
  }

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":281
 *         if py_obj:
 *             return <object>py_obj.obj
 *     return new_lua_object(runtime, n)             # <<<<<<<<<<<<<<
 * 
 * cdef bint py_to_lua(LuaRuntime runtime, object o, bint withnone) except -1:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)__pyx_f_4lupa_5_lupa_new_lua_object(__pyx_v_runtime, __pyx_v_n)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("lupa._lupa.py_from_lua");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_runtime);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":283
 *     return new_lua_object(runtime, n)
 * 
 * cdef bint py_to_lua(LuaRuntime runtime, object o, bint withnone) except -1:             # <<<<<<<<<<<<<<
 *     cdef lua_State *L = runtime._state
 *     cdef bint pushed_values_count = 0
 */

static  int __pyx_f_4lupa_5_lupa_py_to_lua(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *__pyx_v_runtime, PyObject *__pyx_v_o, int __pyx_v_withnone) {
  lua_State *__pyx_v_L;
  int __pyx_v_pushed_values_count;
  int __pyx_v_as_index;
  int __pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  char *__pyx_t_5;
  Py_ssize_t __pyx_t_6;
  double __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  __Pyx_RefNannySetupContext("py_to_lua");
  __Pyx_INCREF((PyObject *)__pyx_v_runtime);
  __Pyx_INCREF(__pyx_v_o);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":284
 * 
 * cdef bint py_to_lua(LuaRuntime runtime, object o, bint withnone) except -1:
 *     cdef lua_State *L = runtime._state             # <<<<<<<<<<<<<<
 *     cdef bint pushed_values_count = 0
 *     cdef bint as_index = 0
 */
  __pyx_v_L = __pyx_v_runtime->_state;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":285
 * cdef bint py_to_lua(LuaRuntime runtime, object o, bint withnone) except -1:
 *     cdef lua_State *L = runtime._state
 *     cdef bint pushed_values_count = 0             # <<<<<<<<<<<<<<
 *     cdef bint as_index = 0
 * 
 */
  __pyx_v_pushed_values_count = 0;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":286
 *     cdef lua_State *L = runtime._state
 *     cdef bint pushed_values_count = 0
 *     cdef bint as_index = 0             # <<<<<<<<<<<<<<
 * 
 *     if o is None:
 */
  __pyx_v_as_index = 0;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":288
 *     cdef bint as_index = 0
 * 
 *     if o is None:             # <<<<<<<<<<<<<<
 *         if withnone:
 *             lua.lua_pushlstring(L, "Py_None", 7)
 */
  __pyx_t_1 = (__pyx_v_o == Py_None);
  if (__pyx_t_1) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":289
 * 
 *     if o is None:
 *         if withnone:             # <<<<<<<<<<<<<<
 *             lua.lua_pushlstring(L, "Py_None", 7)
 *             lua.lua_rawget(L, lua.LUA_REGISTRYINDEX)
 */
    if (__pyx_v_withnone) {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":290
 *     if o is None:
 *         if withnone:
 *             lua.lua_pushlstring(L, "Py_None", 7)             # <<<<<<<<<<<<<<
 *             lua.lua_rawget(L, lua.LUA_REGISTRYINDEX)
 *             if lua.lua_isnil(L, -1):
 */
      lua_pushlstring(__pyx_v_L, __pyx_k__Py_None, 7);

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":291
 *         if withnone:
 *             lua.lua_pushlstring(L, "Py_None", 7)
 *             lua.lua_rawget(L, lua.LUA_REGISTRYINDEX)             # <<<<<<<<<<<<<<
 *             if lua.lua_isnil(L, -1):
 *                 lua.lua_pop(L, 1)
 */
      lua_rawget(__pyx_v_L, LUA_REGISTRYINDEX);

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":292
 *             lua.lua_pushlstring(L, "Py_None", 7)
 *             lua.lua_rawget(L, lua.LUA_REGISTRYINDEX)
 *             if lua.lua_isnil(L, -1):             # <<<<<<<<<<<<<<
 *                 lua.lua_pop(L, 1)
 *                 lua.luaL_error(L, "lost none from registry")
 */
      __pyx_t_1 = lua_isnil(__pyx_v_L, -1);
      if (__pyx_t_1) {

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":293
 *             lua.lua_rawget(L, lua.LUA_REGISTRYINDEX)
 *             if lua.lua_isnil(L, -1):
 *                 lua.lua_pop(L, 1)             # <<<<<<<<<<<<<<
 *                 lua.luaL_error(L, "lost none from registry")
 *         else:
 */
        lua_pop(__pyx_v_L, 1);

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":294
 *             if lua.lua_isnil(L, -1):
 *                 lua.lua_pop(L, 1)
 *                 lua.luaL_error(L, "lost none from registry")             # <<<<<<<<<<<<<<
 *         else:
 *             # Not really needed, but this way we may check for errors
 */
        luaL_error(__pyx_v_L, __pyx_k_12);
        goto __pyx_L5;
      }
      __pyx_L5:;
      goto __pyx_L4;
    }
    /*else*/ {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":298
 *             # Not really needed, but this way we may check for errors
 *             # with pushed_values_count == 0.
 *             lua.lua_pushnil(L)             # <<<<<<<<<<<<<<
 *             pushed_values_count = 1
 *     elif o is True or o is False:
 */
      lua_pushnil(__pyx_v_L);

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":299
 *             # with pushed_values_count == 0.
 *             lua.lua_pushnil(L)
 *             pushed_values_count = 1             # <<<<<<<<<<<<<<
 *     elif o is True or o is False:
 *         lua.lua_pushboolean(L, o is True)
 */
      __pyx_v_pushed_values_count = 1;
    }
    __pyx_L4:;
    goto __pyx_L3;
  }

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":300
 *             lua.lua_pushnil(L)
 *             pushed_values_count = 1
 *     elif o is True or o is False:             # <<<<<<<<<<<<<<
 *         lua.lua_pushboolean(L, o is True)
 *         pushed_values_count = 1
 */
  __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = (__pyx_v_o == __pyx_t_2);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!__pyx_t_1) {
    __pyx_t_2 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = (__pyx_v_o == __pyx_t_2);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_4 = __pyx_t_3;
  } else {
    __pyx_t_4 = __pyx_t_1;
  }
  if (__pyx_t_4) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":301
 *             pushed_values_count = 1
 *     elif o is True or o is False:
 *         lua.lua_pushboolean(L, o is True)             # <<<<<<<<<<<<<<
 *         pushed_values_count = 1
 *     elif isinstance(o, bytes):
 */
    __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = (__pyx_v_o == __pyx_t_2);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    lua_pushboolean(__pyx_v_L, __pyx_t_4);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":302
 *     elif o is True or o is False:
 *         lua.lua_pushboolean(L, o is True)
 *         pushed_values_count = 1             # <<<<<<<<<<<<<<
 *     elif isinstance(o, bytes):
 *         lua.lua_pushlstring(L, <char*>(<bytes>o), len(<bytes>o))
 */
    __pyx_v_pushed_values_count = 1;
    goto __pyx_L3;
  }

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":303
 *         lua.lua_pushboolean(L, o is True)
 *         pushed_values_count = 1
 *     elif isinstance(o, bytes):             # <<<<<<<<<<<<<<
 *         lua.lua_pushlstring(L, <char*>(<bytes>o), len(<bytes>o))
 *         pushed_values_count = 1
 */
  __pyx_t_4 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyBytes_Type))); 
  if (__pyx_t_4) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":304
 *         pushed_values_count = 1
 *     elif isinstance(o, bytes):
 *         lua.lua_pushlstring(L, <char*>(<bytes>o), len(<bytes>o))             # <<<<<<<<<<<<<<
 *         pushed_values_count = 1
 *     elif isinstance(o, int) or isinstance(o, float):
 */
    __pyx_t_5 = PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(((PyObject *)__pyx_v_o) == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
    }
    __pyx_t_6 = PyBytes_GET_SIZE(((PyObject *)((PyObject *)__pyx_v_o))); 
    lua_pushlstring(__pyx_v_L, __pyx_t_5, __pyx_t_6);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":305
 *     elif isinstance(o, bytes):
 *         lua.lua_pushlstring(L, <char*>(<bytes>o), len(<bytes>o))
 *         pushed_values_count = 1             # <<<<<<<<<<<<<<
 *     elif isinstance(o, int) or isinstance(o, float):
 *         lua.lua_pushnumber(L, <lua.lua_Number><double>o)
 */
    __pyx_v_pushed_values_count = 1;
    goto __pyx_L3;
  }

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":306
 *         lua.lua_pushlstring(L, <char*>(<bytes>o), len(<bytes>o))
 *         pushed_values_count = 1
 *     elif isinstance(o, int) or isinstance(o, float):             # <<<<<<<<<<<<<<
 *         lua.lua_pushnumber(L, <lua.lua_Number><double>o)
 *         pushed_values_count = 1
 */
  __pyx_t_4 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyInt_Type))); 
  if (!__pyx_t_4) {
    __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyFloat_Type))); 
    __pyx_t_3 = __pyx_t_1;
  } else {
    __pyx_t_3 = __pyx_t_4;
  }
  if (__pyx_t_3) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":307
 *         pushed_values_count = 1
 *     elif isinstance(o, int) or isinstance(o, float):
 *         lua.lua_pushnumber(L, <lua.lua_Number><double>o)             # <<<<<<<<<<<<<<
 *         pushed_values_count = 1
 *     elif isinstance(o, _LuaObject):
 */
    __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_v_o); if (unlikely((__pyx_t_7 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    lua_pushnumber(__pyx_v_L, ((lua_Number)__pyx_t_7));

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":308
 *     elif isinstance(o, int) or isinstance(o, float):
 *         lua.lua_pushnumber(L, <lua.lua_Number><double>o)
 *         pushed_values_count = 1             # <<<<<<<<<<<<<<
 *     elif isinstance(o, _LuaObject):
 *         if (<_LuaObject>o).runtime is not runtime:
 */
    __pyx_v_pushed_values_count = 1;
    goto __pyx_L3;
  }

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":309
 *         lua.lua_pushnumber(L, <lua.lua_Number><double>o)
 *         pushed_values_count = 1
 *     elif isinstance(o, _LuaObject):             # <<<<<<<<<<<<<<
 *         if (<_LuaObject>o).runtime is not runtime:
 *             raise LuaError("cannot mix objects from different Lua runtimes")
 */
  __pyx_t_3 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)__pyx_ptype_4lupa_5_lupa__LuaObject))); 
  if (__pyx_t_3) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":310
 *         pushed_values_count = 1
 *     elif isinstance(o, _LuaObject):
 *         if (<_LuaObject>o).runtime is not runtime:             # <<<<<<<<<<<<<<
 *             raise LuaError("cannot mix objects from different Lua runtimes")
 *         lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, (<_LuaObject>o)._ref)
 */
    __pyx_t_2 = PyObject_GetAttr(__pyx_v_o, __pyx_n_s__runtime); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = (__pyx_t_2 != ((PyObject *)__pyx_v_runtime));
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_3) {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":311
 *     elif isinstance(o, _LuaObject):
 *         if (<_LuaObject>o).runtime is not runtime:
 *             raise LuaError("cannot mix objects from different Lua runtimes")             # <<<<<<<<<<<<<<
 *         lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, (<_LuaObject>o)._ref)
 *         pushed_values_count = 1
 */
      __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__LuaError); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_INCREF(((PyObject *)__pyx_kp_s_13));
      PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_kp_s_13));
      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_13));
      __pyx_t_9 = PyObject_Call(__pyx_t_2, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_Raise(__pyx_t_9, 0, 0);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":312
 *         if (<_LuaObject>o).runtime is not runtime:
 *             raise LuaError("cannot mix objects from different Lua runtimes")
 *         lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, (<_LuaObject>o)._ref)             # <<<<<<<<<<<<<<
 *         pushed_values_count = 1
 *     else:
 */
    lua_rawgeti(__pyx_v_L, LUA_REGISTRYINDEX, ((struct __pyx_obj_4lupa_5_lupa__LuaObject *)__pyx_v_o)->_ref);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":313
 *             raise LuaError("cannot mix objects from different Lua runtimes")
 *         lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, (<_LuaObject>o)._ref)
 *         pushed_values_count = 1             # <<<<<<<<<<<<<<
 *     else:
 *         as_index =  isinstance(o, dict) or isinstance(o, list) or isinstance(o, tuple)
 */
    __pyx_v_pushed_values_count = 1;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":315
 *         pushed_values_count = 1
 *     else:
 *         as_index =  isinstance(o, dict) or isinstance(o, list) or isinstance(o, tuple)             # <<<<<<<<<<<<<<
 *         pushed_values_count = py_to_lua_custom(runtime, o, as_index)
 *         if pushed_values_count and not as_index and hasattr(o, '__call__'):
 */
    __pyx_t_3 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyDict_Type))); 
    if (!__pyx_t_3) {
      __pyx_t_4 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyList_Type))); 
      if (!__pyx_t_4) {
        __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyTuple_Type))); 
        __pyx_t_10 = __pyx_t_1;
      } else {
        __pyx_t_10 = __pyx_t_4;
      }
      __pyx_t_4 = __pyx_t_10;
    } else {
      __pyx_t_4 = __pyx_t_3;
    }
    __pyx_v_as_index = __pyx_t_4;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":316
 *     else:
 *         as_index =  isinstance(o, dict) or isinstance(o, list) or isinstance(o, tuple)
 *         pushed_values_count = py_to_lua_custom(runtime, o, as_index)             # <<<<<<<<<<<<<<
 *         if pushed_values_count and not as_index and hasattr(o, '__call__'):
 *             lua.lua_pushcclosure(L, <lua.lua_CFunction>py_asfunc_call, 1)
 */
    __pyx_v_pushed_values_count = __pyx_f_4lupa_5_lupa_py_to_lua_custom(__pyx_v_runtime, __pyx_v_o, __pyx_v_as_index);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":317
 *         as_index =  isinstance(o, dict) or isinstance(o, list) or isinstance(o, tuple)
 *         pushed_values_count = py_to_lua_custom(runtime, o, as_index)
 *         if pushed_values_count and not as_index and hasattr(o, '__call__'):             # <<<<<<<<<<<<<<
 *             lua.lua_pushcclosure(L, <lua.lua_CFunction>py_asfunc_call, 1)
 *     return pushed_values_count
 */
    if (__pyx_v_pushed_values_count) {
      __pyx_t_4 = (!__pyx_v_as_index);
      if (__pyx_t_4) {
        __pyx_t_3 = PyObject_HasAttr(__pyx_v_o, ((PyObject *)__pyx_n_s____call__)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_10 = __pyx_t_3;
      } else {
        __pyx_t_10 = __pyx_t_4;
      }
      __pyx_t_4 = __pyx_t_10;
    } else {
      __pyx_t_4 = __pyx_v_pushed_values_count;
    }
    if (__pyx_t_4) {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":318
 *         pushed_values_count = py_to_lua_custom(runtime, o, as_index)
 *         if pushed_values_count and not as_index and hasattr(o, '__call__'):
 *             lua.lua_pushcclosure(L, <lua.lua_CFunction>py_asfunc_call, 1)             # <<<<<<<<<<<<<<
 *     return pushed_values_count
 * 
 */
      lua_pushcclosure(__pyx_v_L, ((lua_CFunction)__pyx_f_4lupa_5_lupa_py_asfunc_call), 1);
      goto __pyx_L7;
    }
    __pyx_L7:;
  }
  __pyx_L3:;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":319
 *         if pushed_values_count and not as_index and hasattr(o, '__call__'):
 *             lua.lua_pushcclosure(L, <lua.lua_CFunction>py_asfunc_call, 1)
 *     return pushed_values_count             # <<<<<<<<<<<<<<
 * 
 * cdef bint py_to_lua_custom(LuaRuntime runtime, object o, int as_index):
 */
  __pyx_r = __pyx_v_pushed_values_count;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("lupa._lupa.py_to_lua");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_runtime);
  __Pyx_DECREF(__pyx_v_o);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":321
 *     return pushed_values_count
 * 
 * cdef bint py_to_lua_custom(LuaRuntime runtime, object o, int as_index):             # <<<<<<<<<<<<<<
 *     cdef lua_State *L = runtime._state
 *     cdef py_object *py_obj = <py_object*> lua.lua_newuserdata(L, sizeof(py_object))
 */

static  int __pyx_f_4lupa_5_lupa_py_to_lua_custom(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *__pyx_v_runtime, PyObject *__pyx_v_o, int __pyx_v_as_index) {
  lua_State *__pyx_v_L;
  struct __pyx_t_4lupa_5_lupa_py_object *__pyx_v_py_obj;
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("py_to_lua_custom");
  __Pyx_INCREF((PyObject *)__pyx_v_runtime);
  __Pyx_INCREF(__pyx_v_o);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":322
 * 
 * cdef bint py_to_lua_custom(LuaRuntime runtime, object o, int as_index):
 *     cdef lua_State *L = runtime._state             # <<<<<<<<<<<<<<
 *     cdef py_object *py_obj = <py_object*> lua.lua_newuserdata(L, sizeof(py_object))
 *     if py_obj:
 */
  __pyx_v_L = __pyx_v_runtime->_state;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":323
 * cdef bint py_to_lua_custom(LuaRuntime runtime, object o, int as_index):
 *     cdef lua_State *L = runtime._state
 *     cdef py_object *py_obj = <py_object*> lua.lua_newuserdata(L, sizeof(py_object))             # <<<<<<<<<<<<<<
 *     if py_obj:
 *         cpython.ref.Py_INCREF(o)
 */
  __pyx_v_py_obj = ((struct __pyx_t_4lupa_5_lupa_py_object *)lua_newuserdata(__pyx_v_L, (sizeof(struct __pyx_t_4lupa_5_lupa_py_object))));

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":324
 *     cdef lua_State *L = runtime._state
 *     cdef py_object *py_obj = <py_object*> lua.lua_newuserdata(L, sizeof(py_object))
 *     if py_obj:             # <<<<<<<<<<<<<<
 *         cpython.ref.Py_INCREF(o)
 *         cpython.ref.Py_INCREF(runtime)
 */
  __pyx_t_1 = (__pyx_v_py_obj != 0);
  if (__pyx_t_1) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":325
 *     cdef py_object *py_obj = <py_object*> lua.lua_newuserdata(L, sizeof(py_object))
 *     if py_obj:
 *         cpython.ref.Py_INCREF(o)             # <<<<<<<<<<<<<<
 *         cpython.ref.Py_INCREF(runtime)
 *         py_obj.obj = <PyObject*>o
 */
    Py_INCREF(__pyx_v_o);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":326
 *     if py_obj:
 *         cpython.ref.Py_INCREF(o)
 *         cpython.ref.Py_INCREF(runtime)             # <<<<<<<<<<<<<<
 *         py_obj.obj = <PyObject*>o
 *         py_obj.runtime = <PyObject*>runtime
 */
    Py_INCREF(((PyObject *)__pyx_v_runtime));

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":327
 *         cpython.ref.Py_INCREF(o)
 *         cpython.ref.Py_INCREF(runtime)
 *         py_obj.obj = <PyObject*>o             # <<<<<<<<<<<<<<
 *         py_obj.runtime = <PyObject*>runtime
 *         py_obj.as_index = as_index
 */
    __pyx_v_py_obj->obj = ((PyObject *)__pyx_v_o);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":328
 *         cpython.ref.Py_INCREF(runtime)
 *         py_obj.obj = <PyObject*>o
 *         py_obj.runtime = <PyObject*>runtime             # <<<<<<<<<<<<<<
 *         py_obj.as_index = as_index
 *         lua.luaL_getmetatable(L, POBJECT)
 */
    __pyx_v_py_obj->runtime = ((PyObject *)__pyx_v_runtime);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":329
 *         py_obj.obj = <PyObject*>o
 *         py_obj.runtime = <PyObject*>runtime
 *         py_obj.as_index = as_index             # <<<<<<<<<<<<<<
 *         lua.luaL_getmetatable(L, POBJECT)
 *         lua.lua_setmetatable(L, -2)
 */
    __pyx_v_py_obj->as_index = __pyx_v_as_index;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":330
 *         py_obj.runtime = <PyObject*>runtime
 *         py_obj.as_index = as_index
 *         lua.luaL_getmetatable(L, POBJECT)             # <<<<<<<<<<<<<<
 *         lua.lua_setmetatable(L, -2)
 *         return 1 # values pushed
 */
    luaL_getmetatable(__pyx_v_L, __pyx_k__POBJECT);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":331
 *         py_obj.as_index = as_index
 *         lua.luaL_getmetatable(L, POBJECT)
 *         lua.lua_setmetatable(L, -2)             # <<<<<<<<<<<<<<
 *         return 1 # values pushed
 *     else:
 */
    lua_setmetatable(__pyx_v_L, -2);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":332
 *         lua.luaL_getmetatable(L, POBJECT)
 *         lua.lua_setmetatable(L, -2)
 *         return 1 # values pushed             # <<<<<<<<<<<<<<
 *     else:
 *         lua.luaL_error(L, "failed to allocate userdata object")
 */
    __pyx_r = 1;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":334
 *         return 1 # values pushed
 *     else:
 *         lua.luaL_error(L, "failed to allocate userdata object")             # <<<<<<<<<<<<<<
 *         return 0 # values pushed
 * 
 */
    luaL_error(__pyx_v_L, __pyx_k_14);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":335
 *     else:
 *         lua.luaL_error(L, "failed to allocate userdata object")
 *         return 0 # values pushed             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_r = 0;
    goto __pyx_L0;
  }
  __pyx_L3:;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_runtime);
  __Pyx_DECREF(__pyx_v_o);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":338
 * 
 * 
 * cdef run_lua(LuaRuntime runtime, bytes lua_code):             # <<<<<<<<<<<<<<
 *     # locks the runtime
 *     cdef lua_State* L = runtime._state
 */

static  PyObject *__pyx_f_4lupa_5_lupa_run_lua(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *__pyx_v_runtime, PyObject *__pyx_v_lua_code) {
  lua_State *__pyx_v_L;
  int __pyx_v_result;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  char *__pyx_t_2;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  __Pyx_RefNannySetupContext("run_lua");
  __Pyx_INCREF((PyObject *)__pyx_v_runtime);
  __Pyx_INCREF(__pyx_v_lua_code);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":340
 * cdef run_lua(LuaRuntime runtime, bytes lua_code):
 *     # locks the runtime
 *     cdef lua_State* L = runtime._state             # <<<<<<<<<<<<<<
 *     cdef bint result
 *     runtime.lock()
 */
  __pyx_v_L = __pyx_v_runtime->_state;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":342
 *     cdef lua_State* L = runtime._state
 *     cdef bint result
 *     runtime.lock()             # <<<<<<<<<<<<<<
 *     try:
 *         if lua.luaL_loadbuffer(L, lua_code, len(lua_code), '<python>'):
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime *)__pyx_v_runtime->__pyx_vtab)->lock(__pyx_v_runtime); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":343
 *     cdef bint result
 *     runtime.lock()
 *     try:             # <<<<<<<<<<<<<<
 *         if lua.luaL_loadbuffer(L, lua_code, len(lua_code), '<python>'):
 *             raise LuaError("error loading code: %s" % lua.lua_tostring(L, -1))
 */
  /*try:*/ {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":344
 *     runtime.lock()
 *     try:
 *         if lua.luaL_loadbuffer(L, lua_code, len(lua_code), '<python>'):             # <<<<<<<<<<<<<<
 *             raise LuaError("error loading code: %s" % lua.lua_tostring(L, -1))
 *         with nogil:
 */
    __pyx_t_2 = PyBytes_AsString(((PyObject *)__pyx_v_lua_code)); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L4;}
    if (unlikely(__pyx_v_lua_code == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L4;} 
    }
    __pyx_t_3 = PyBytes_GET_SIZE(((PyObject *)__pyx_v_lua_code)); 
    __pyx_t_1 = luaL_loadbuffer(__pyx_v_L, __pyx_t_2, __pyx_t_3, __pyx_k_15);
    if (__pyx_t_1) {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":345
 *     try:
 *         if lua.luaL_loadbuffer(L, lua_code, len(lua_code), '<python>'):
 *             raise LuaError("error loading code: %s" % lua.lua_tostring(L, -1))             # <<<<<<<<<<<<<<
 *         with nogil:
 *             result = lua.lua_pcall(L, 0, 1, 0)
 */
      __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__LuaError); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = PyBytes_FromString(lua_tostring(__pyx_v_L, -1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_5));
      __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_16), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_6));
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_6));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
      __pyx_t_6 = 0;
      __pyx_t_6 = PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_Raise(__pyx_t_6, 0, 0);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L4;}
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":346
 *         if lua.luaL_loadbuffer(L, lua_code, len(lua_code), '<python>'):
 *             raise LuaError("error loading code: %s" % lua.lua_tostring(L, -1))
 *         with nogil:             # <<<<<<<<<<<<<<
 *             result = lua.lua_pcall(L, 0, 1, 0)
 *         runtime.reraise_on_exception()
 */
    { PyThreadState *_save;
      Py_UNBLOCK_THREADS
      /*try:*/ {

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":347
 *             raise LuaError("error loading code: %s" % lua.lua_tostring(L, -1))
 *         with nogil:
 *             result = lua.lua_pcall(L, 0, 1, 0)             # <<<<<<<<<<<<<<
 *         runtime.reraise_on_exception()
 *         if result:
 */
        __pyx_v_result = lua_pcall(__pyx_v_L, 0, 1, 0);
      }
      /*finally:*/ {

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":346
 *         if lua.luaL_loadbuffer(L, lua_code, len(lua_code), '<python>'):
 *             raise LuaError("error loading code: %s" % lua.lua_tostring(L, -1))
 *         with nogil:             # <<<<<<<<<<<<<<
 *             result = lua.lua_pcall(L, 0, 1, 0)
 *         runtime.reraise_on_exception()
 */
        Py_BLOCK_THREADS
      }
    }

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":348
 *         with nogil:
 *             result = lua.lua_pcall(L, 0, 1, 0)
 *         runtime.reraise_on_exception()             # <<<<<<<<<<<<<<
 *         if result:
 *             raise LuaError("error executing code: %s" % lua.lua_tostring(L, -1))
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime *)__pyx_v_runtime->__pyx_vtab)->reraise_on_exception(__pyx_v_runtime); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L4;}

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":349
 *             result = lua.lua_pcall(L, 0, 1, 0)
 *         runtime.reraise_on_exception()
 *         if result:             # <<<<<<<<<<<<<<
 *             raise LuaError("error executing code: %s" % lua.lua_tostring(L, -1))
 *         try:
 */
    if (__pyx_v_result) {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":350
 *         runtime.reraise_on_exception()
 *         if result:
 *             raise LuaError("error executing code: %s" % lua.lua_tostring(L, -1))             # <<<<<<<<<<<<<<
 *         try:
 *             return py_from_lua(runtime, -1)
 */
      __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__LuaError); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = PyBytes_FromString(lua_tostring(__pyx_v_L, -1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_5));
      __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_4));
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_4));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
      __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_Call(__pyx_t_6, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L4;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_Raise(__pyx_t_4, 0, 0);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L4;}
      goto __pyx_L10;
    }
    __pyx_L10:;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":351
 *         if result:
 *             raise LuaError("error executing code: %s" % lua.lua_tostring(L, -1))
 *         try:             # <<<<<<<<<<<<<<
 *             return py_from_lua(runtime, -1)
 *         finally:
 */
    /*try:*/ {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":352
 *             raise LuaError("error executing code: %s" % lua.lua_tostring(L, -1))
 *         try:
 *             return py_from_lua(runtime, -1)             # <<<<<<<<<<<<<<
 *         finally:
 *             lua.lua_settop(L, 0)
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_4 = __pyx_f_4lupa_5_lupa_py_from_lua(__pyx_v_runtime, -1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L12;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_r = __pyx_t_4;
      __pyx_t_4 = 0;
      goto __pyx_L11;
    }
    /*finally:*/ {
      int __pyx_why;
      PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb;
      int __pyx_exc_lineno;
      __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
      __pyx_why = 0; goto __pyx_L13;
      __pyx_L11: __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
      __pyx_why = 3; goto __pyx_L13;
      __pyx_L12: {
        __pyx_why = 4;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb);
        __pyx_exc_lineno = __pyx_lineno;
        goto __pyx_L13;
      }
      __pyx_L13:;

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":354
 *             return py_from_lua(runtime, -1)
 *         finally:
 *             lua.lua_settop(L, 0)             # <<<<<<<<<<<<<<
 *     finally:
 *         runtime.unlock()
 */
      lua_settop(__pyx_v_L, 0);
      switch (__pyx_why) {
        case 3: goto __pyx_L3;
        case 4: {
          __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb);
          __pyx_lineno = __pyx_exc_lineno;
          __pyx_exc_type = 0;
          __pyx_exc_value = 0;
          __pyx_exc_tb = 0;
          goto __pyx_L4;
        }
      }
    }
  }
  /*finally:*/ {
    int __pyx_why;
    PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb;
    int __pyx_exc_lineno;
    __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
    __pyx_why = 0; goto __pyx_L5;
    __pyx_L3: __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
    __pyx_why = 3; goto __pyx_L5;
    __pyx_L4: {
      __pyx_why = 4;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb);
      __pyx_exc_lineno = __pyx_lineno;
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":356
 *             lua.lua_settop(L, 0)
 *     finally:
 *         runtime.unlock()             # <<<<<<<<<<<<<<
 * 
 * 
 */
    ((struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime *)__pyx_v_runtime->__pyx_vtab)->unlock(__pyx_v_runtime);
    switch (__pyx_why) {
      case 3: goto __pyx_L0;
      case 4: {
        __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb);
        __pyx_lineno = __pyx_exc_lineno;
        __pyx_exc_type = 0;
        __pyx_exc_value = 0;
        __pyx_exc_tb = 0;
        goto __pyx_L1_error;
      }
    }
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("lupa._lupa.run_lua");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_runtime);
  __Pyx_DECREF(__pyx_v_lua_code);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":359
 * 
 * 
 * cdef call_lua(LuaRuntime runtime, tuple args):             # <<<<<<<<<<<<<<
 *     # does not lock the runtime!
 *     cdef lua_State *L = runtime._state
 */

static  PyObject *__pyx_f_4lupa_5_lupa_call_lua(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *__pyx_v_runtime, PyObject *__pyx_v_args) {
  lua_State *__pyx_v_L;
  Py_ssize_t __pyx_v_i;
  Py_ssize_t __pyx_v_nargs;
  int __pyx_v_result_status;
  PyObject *__pyx_v_arg;
  PyObject *__pyx_r = NULL;
  Py_ssize_t __pyx_t_1;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  __Pyx_RefNannySetupContext("call_lua");
  __Pyx_INCREF((PyObject *)__pyx_v_runtime);
  __Pyx_INCREF(__pyx_v_args);
  __pyx_v_arg = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":361
 * cdef call_lua(LuaRuntime runtime, tuple args):
 *     # does not lock the runtime!
 *     cdef lua_State *L = runtime._state             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t i, nargs
 *     cdef int result_status
 */
  __pyx_v_L = __pyx_v_runtime->_state;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":365
 *     cdef int result_status
 *     # convert arguments
 *     for i, arg in enumerate(args):             # <<<<<<<<<<<<<<
 *         if not py_to_lua(runtime, arg, 0):
 *             lua.lua_settop(L, 0)
 */
  __pyx_t_1 = 0;
  if (likely(((PyObject *)__pyx_v_args) != Py_None)) {
    __pyx_t_2 = 0; __pyx_t_3 = ((PyObject *)__pyx_v_args); __Pyx_INCREF(__pyx_t_3);
  } else {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  for (;;) {
    if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
    __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++;
    __Pyx_DECREF(__pyx_v_arg);
    __pyx_v_arg = __pyx_t_4;
    __pyx_t_4 = 0;
    __pyx_v_i = __pyx_t_1;
    __pyx_t_1 = (__pyx_t_1 + 1);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":366
 *     # convert arguments
 *     for i, arg in enumerate(args):
 *         if not py_to_lua(runtime, arg, 0):             # <<<<<<<<<<<<<<
 *             lua.lua_settop(L, 0)
 *             raise TypeError("failed to convert argument at index %d" % i)
 */
    __pyx_t_5 = __pyx_f_4lupa_5_lupa_py_to_lua(__pyx_v_runtime, __pyx_v_arg, 0); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_6 = (!__pyx_t_5);
    if (__pyx_t_6) {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":367
 *     for i, arg in enumerate(args):
 *         if not py_to_lua(runtime, arg, 0):
 *             lua.lua_settop(L, 0)             # <<<<<<<<<<<<<<
 *             raise TypeError("failed to convert argument at index %d" % i)
 * 
 */
      lua_settop(__pyx_v_L, 0);

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":368
 *         if not py_to_lua(runtime, arg, 0):
 *             lua.lua_settop(L, 0)
 *             raise TypeError("failed to convert argument at index %d" % i)             # <<<<<<<<<<<<<<
 * 
 *     # call into Lua
 */
      __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_19), __pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_7));
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_7));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
      __pyx_t_7 = 0;
      __pyx_t_7 = PyObject_Call(__pyx_builtin_TypeError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_Raise(__pyx_t_7, 0, 0);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L5;
    }
    __pyx_L5:;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":371
 * 
 *     # call into Lua
 *     nargs = len(args)             # <<<<<<<<<<<<<<
 *     with nogil:
 *         result_status = lua.lua_pcall(L, nargs, lua.LUA_MULTRET, 0)
 */
  if (unlikely(__pyx_v_args == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
  }
  __pyx_t_1 = PyTuple_GET_SIZE(((PyObject *)__pyx_v_args)); 
  __pyx_v_nargs = __pyx_t_1;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":372
 *     # call into Lua
 *     nargs = len(args)
 *     with nogil:             # <<<<<<<<<<<<<<
 *         result_status = lua.lua_pcall(L, nargs, lua.LUA_MULTRET, 0)
 *     runtime.reraise_on_exception()
 */
  { PyThreadState *_save;
    Py_UNBLOCK_THREADS
    /*try:*/ {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":373
 *     nargs = len(args)
 *     with nogil:
 *         result_status = lua.lua_pcall(L, nargs, lua.LUA_MULTRET, 0)             # <<<<<<<<<<<<<<
 *     runtime.reraise_on_exception()
 *     if result_status:
 */
      __pyx_v_result_status = lua_pcall(__pyx_v_L, __pyx_v_nargs, LUA_MULTRET, 0);
    }
    /*finally:*/ {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":372
 *     # call into Lua
 *     nargs = len(args)
 *     with nogil:             # <<<<<<<<<<<<<<
 *         result_status = lua.lua_pcall(L, nargs, lua.LUA_MULTRET, 0)
 *     runtime.reraise_on_exception()
 */
      Py_BLOCK_THREADS
    }
  }

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":374
 *     with nogil:
 *         result_status = lua.lua_pcall(L, nargs, lua.LUA_MULTRET, 0)
 *     runtime.reraise_on_exception()             # <<<<<<<<<<<<<<
 *     if result_status:
 *         raise LuaError("error: %s" % lua.lua_tostring(L, -1))
 */
  __pyx_t_8 = ((struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime *)__pyx_v_runtime->__pyx_vtab)->reraise_on_exception(__pyx_v_runtime); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":375
 *         result_status = lua.lua_pcall(L, nargs, lua.LUA_MULTRET, 0)
 *     runtime.reraise_on_exception()
 *     if result_status:             # <<<<<<<<<<<<<<
 *         raise LuaError("error: %s" % lua.lua_tostring(L, -1))
 * 
 */
  if (__pyx_v_result_status) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":376
 *     runtime.reraise_on_exception()
 *     if result_status:
 *         raise LuaError("error: %s" % lua.lua_tostring(L, -1))             # <<<<<<<<<<<<<<
 * 
 *     # extract return values
 */
    __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__LuaError); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = PyBytes_FromString(lua_tostring(__pyx_v_L, -1)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_20), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_4));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
    __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":379
 * 
 *     # extract return values
 *     try:             # <<<<<<<<<<<<<<
 *         nargs = lua.lua_gettop(L)
 *         if nargs == 1:
 */
  /*try:*/ {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":380
 *     # extract return values
 *     try:
 *         nargs = lua.lua_gettop(L)             # <<<<<<<<<<<<<<
 *         if nargs == 1:
 *             return py_from_lua(runtime, 1)
 */
    __pyx_v_nargs = lua_gettop(__pyx_v_L);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":381
 *     try:
 *         nargs = lua.lua_gettop(L)
 *         if nargs == 1:             # <<<<<<<<<<<<<<
 *             return py_from_lua(runtime, 1)
 *         elif nargs == 0:
 */
    switch (__pyx_v_nargs) {
      case 1:

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":382
 *         nargs = lua.lua_gettop(L)
 *         if nargs == 1:
 *             return py_from_lua(runtime, 1)             # <<<<<<<<<<<<<<
 *         elif nargs == 0:
 *             return None
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_4 = __pyx_f_4lupa_5_lupa_py_from_lua(__pyx_v_runtime, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 382; __pyx_clineno = __LINE__; goto __pyx_L11;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_r = __pyx_t_4;
      __pyx_t_4 = 0;
      goto __pyx_L10;
      break;

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":383
 *         if nargs == 1:
 *             return py_from_lua(runtime, 1)
 *         elif nargs == 0:             # <<<<<<<<<<<<<<
 *             return None
 *         else:
 */
      case 0:

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":384
 *             return py_from_lua(runtime, 1)
 *         elif nargs == 0:
 *             return None             # <<<<<<<<<<<<<<
 *         else:
 *             return tuple([ py_from_lua(runtime, i+1) for i in range(nargs) ])
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(Py_None);
      __pyx_r = Py_None;
      goto __pyx_L10;
      break;
      default:

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":386
 *             return None
 *         else:
 *             return tuple([ py_from_lua(runtime, i+1) for i in range(nargs) ])             # <<<<<<<<<<<<<<
 *     finally:
 *         lua.lua_settop(L, 0)
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L11;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_4));
      __pyx_t_1 = __pyx_v_nargs;
      for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
        __pyx_v_i = __pyx_t_2;
        __pyx_t_7 = __pyx_f_4lupa_5_lupa_py_from_lua(__pyx_v_runtime, (__pyx_v_i + 1)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L11;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = PyList_Append(__pyx_t_4, (PyObject*)__pyx_t_7); if (unlikely(__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L11;}
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
      __pyx_t_7 = ((PyObject *)PyList_AsTuple(__pyx_t_4)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L11;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_7));
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      __pyx_r = ((PyObject *)__pyx_t_7);
      __pyx_t_7 = 0;
      goto __pyx_L10;
      break;
    }
  }
  /*finally:*/ {
    int __pyx_why;
    PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb;
    int __pyx_exc_lineno;
    __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
    __pyx_why = 0; goto __pyx_L12;
    __pyx_L10: __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
    __pyx_why = 3; goto __pyx_L12;
    __pyx_L11: {
      __pyx_why = 4;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb);
      __pyx_exc_lineno = __pyx_lineno;
      goto __pyx_L12;
    }
    __pyx_L12:;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":388
 *             return tuple([ py_from_lua(runtime, i+1) for i in range(nargs) ])
 *     finally:
 *         lua.lua_settop(L, 0)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    lua_settop(__pyx_v_L, 0);
    switch (__pyx_why) {
      case 3: goto __pyx_L0;
      case 4: {
        __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb);
        __pyx_lineno = __pyx_exc_lineno;
        __pyx_exc_type = 0;
        __pyx_exc_value = 0;
        __pyx_exc_tb = 0;
        goto __pyx_L1_error;
      }
    }
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("lupa._lupa.call_lua");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_arg);
  __Pyx_DECREF((PyObject *)__pyx_v_runtime);
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":396
 * # ref-counting support for Python objects
 * 
 * cdef void decref_with_gil(py_object *py_obj) with gil:             # <<<<<<<<<<<<<<
 *     cpython.ref.Py_XDECREF(py_obj.obj)
 *     cpython.ref.Py_XDECREF(py_obj.runtime)
 */

static  void __pyx_f_4lupa_5_lupa_decref_with_gil(struct __pyx_t_4lupa_5_lupa_py_object *__pyx_v_py_obj) {
  PyGILState_STATE _save = PyGILState_Ensure();
  __Pyx_RefNannySetupContext("decref_with_gil");

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":397
 * 
 * cdef void decref_with_gil(py_object *py_obj) with gil:
 *     cpython.ref.Py_XDECREF(py_obj.obj)             # <<<<<<<<<<<<<<
 *     cpython.ref.Py_XDECREF(py_obj.runtime)
 * 
 */
  Py_XDECREF(__pyx_v_py_obj->obj);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":398
 * cdef void decref_with_gil(py_object *py_obj) with gil:
 *     cpython.ref.Py_XDECREF(py_obj.obj)
 *     cpython.ref.Py_XDECREF(py_obj.runtime)             # <<<<<<<<<<<<<<
 * 
 * cdef int py_object_gc(lua_State* L):
 */
  Py_XDECREF(__pyx_v_py_obj->runtime);

  __Pyx_RefNannyFinishContext();
  PyGILState_Release(_save);
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":400
 *     cpython.ref.Py_XDECREF(py_obj.runtime)
 * 
 * cdef int py_object_gc(lua_State* L):             # <<<<<<<<<<<<<<
 *     cdef py_object *py_obj = <py_object*> lua.luaL_checkudata(L, 1, POBJECT)
 *     if py_obj is not NULL and py_obj.obj is not NULL:
 */

static  int __pyx_f_4lupa_5_lupa_py_object_gc(lua_State *__pyx_v_L) {
  struct __pyx_t_4lupa_5_lupa_py_object *__pyx_v_py_obj;
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("py_object_gc");

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":401
 * 
 * cdef int py_object_gc(lua_State* L):
 *     cdef py_object *py_obj = <py_object*> lua.luaL_checkudata(L, 1, POBJECT)             # <<<<<<<<<<<<<<
 *     if py_obj is not NULL and py_obj.obj is not NULL:
 *         decref_with_gil(py_obj)
 */
  __pyx_v_py_obj = ((struct __pyx_t_4lupa_5_lupa_py_object *)luaL_checkudata(__pyx_v_L, 1, __pyx_k__POBJECT));

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":402
 * cdef int py_object_gc(lua_State* L):
 *     cdef py_object *py_obj = <py_object*> lua.luaL_checkudata(L, 1, POBJECT)
 *     if py_obj is not NULL and py_obj.obj is not NULL:             # <<<<<<<<<<<<<<
 *         decref_with_gil(py_obj)
 *     return 0
 */
  __pyx_t_1 = (__pyx_v_py_obj != NULL);
  if (__pyx_t_1) {
    __pyx_t_2 = (__pyx_v_py_obj->obj != NULL);
    __pyx_t_3 = __pyx_t_2;
  } else {
    __pyx_t_3 = __pyx_t_1;
  }
  if (__pyx_t_3) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":403
 *     cdef py_object *py_obj = <py_object*> lua.luaL_checkudata(L, 1, POBJECT)
 *     if py_obj is not NULL and py_obj.obj is not NULL:
 *         decref_with_gil(py_obj)             # <<<<<<<<<<<<<<
 *     return 0
 * 
 */
    __pyx_f_4lupa_5_lupa_decref_with_gil(__pyx_v_py_obj);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":404
 *     if py_obj is not NULL and py_obj.obj is not NULL:
 *         decref_with_gil(py_obj)
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * # calling Python objects
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":408
 * # calling Python objects
 * 
 * cdef bint call_python(LuaRuntime runtime, py_object* py_obj) except -1:             # <<<<<<<<<<<<<<
 *     cdef lua_State *L = runtime._state
 *     cdef int nargs = lua.lua_gettop(L) - 1
 */

static  int __pyx_f_4lupa_5_lupa_call_python(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *__pyx_v_runtime, struct __pyx_t_4lupa_5_lupa_py_object *__pyx_v_py_obj) {
  lua_State *__pyx_v_L;
  int __pyx_v_nargs;
  int __pyx_v_ret;
  PyObject *__pyx_v_args;
  PyObject *__pyx_v_i;
  int __pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  __Pyx_RefNannySetupContext("call_python");
  __Pyx_INCREF((PyObject *)__pyx_v_runtime);
  __pyx_v_args = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_i = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":409
 * 
 * cdef bint call_python(LuaRuntime runtime, py_object* py_obj) except -1:
 *     cdef lua_State *L = runtime._state             # <<<<<<<<<<<<<<
 *     cdef int nargs = lua.lua_gettop(L) - 1
 *     cdef bint ret = 0
 */
  __pyx_v_L = __pyx_v_runtime->_state;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":410
 * cdef bint call_python(LuaRuntime runtime, py_object* py_obj) except -1:
 *     cdef lua_State *L = runtime._state
 *     cdef int nargs = lua.lua_gettop(L) - 1             # <<<<<<<<<<<<<<
 *     cdef bint ret = 0
 * 
 */
  __pyx_v_nargs = (lua_gettop(__pyx_v_L) - 1);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":411
 *     cdef lua_State *L = runtime._state
 *     cdef int nargs = lua.lua_gettop(L) - 1
 *     cdef bint ret = 0             # <<<<<<<<<<<<<<
 * 
 *     if not py_obj:
 */
  __pyx_v_ret = 0;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":413
 *     cdef bint ret = 0
 * 
 *     if not py_obj:             # <<<<<<<<<<<<<<
 *         lua.luaL_argerror(L, 1, "not a python object")
 *         return 0
 */
  __pyx_t_1 = (!(__pyx_v_py_obj != 0));
  if (__pyx_t_1) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":414
 * 
 *     if not py_obj:
 *         lua.luaL_argerror(L, 1, "not a python object")             # <<<<<<<<<<<<<<
 *         return 0
 * 
 */
    luaL_argerror(__pyx_v_L, 1, __pyx_k_21);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":415
 *     if not py_obj:
 *         lua.luaL_argerror(L, 1, "not a python object")
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     args = [ py_from_lua(runtime, i+2) for i in range(nargs) ]
 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":417
 *         return 0
 * 
 *     args = [ py_from_lua(runtime, i+2) for i in range(nargs) ]             # <<<<<<<<<<<<<<
 *     return py_to_lua(runtime, (<object>py_obj.obj)(*args), 0)
 * 
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_4 = PyInt_FromLong(__pyx_v_nargs); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_builtin_range, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyList_CheckExact(__pyx_t_4) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_3 = 0; __pyx_t_5 = __pyx_t_4; __Pyx_INCREF(__pyx_t_5);
  } else {
    __pyx_t_3 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (likely(PyList_CheckExact(__pyx_t_5))) {
      if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_5)) break;
      __pyx_t_4 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++;
    } else if (likely(PyTuple_CheckExact(__pyx_t_5))) {
      if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
      __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++;
    } else {
      __pyx_t_4 = PyIter_Next(__pyx_t_5);
      if (!__pyx_t_4) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_DECREF(__pyx_v_i);
    __pyx_v_i = __pyx_t_4;
    __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Add(__pyx_v_i, __pyx_int_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __pyx_f_4lupa_5_lupa_py_from_lua(__pyx_v_runtime, __pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = PyList_Append(__pyx_t_2, (PyObject*)__pyx_t_4); if (unlikely(__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_INCREF(((PyObject *)__pyx_t_2));
  __Pyx_DECREF(((PyObject *)__pyx_v_args));
  __pyx_v_args = __pyx_t_2;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":418
 * 
 *     args = [ py_from_lua(runtime, i+2) for i in range(nargs) ]
 *     return py_to_lua(runtime, (<object>py_obj.obj)(*args), 0)             # <<<<<<<<<<<<<<
 * 
 * cdef int py_call_with_gil(lua_State* L, py_object *py_obj) with gil:
 */
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_5 = PyObject_Call(((PyObject *)__pyx_v_py_obj->obj), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_1 = __pyx_f_4lupa_5_lupa_py_to_lua(__pyx_v_runtime, __pyx_t_5, 0); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("lupa._lupa.call_python");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_DECREF(__pyx_v_i);
  __Pyx_DECREF((PyObject *)__pyx_v_runtime);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":420
 *     return py_to_lua(runtime, (<object>py_obj.obj)(*args), 0)
 * 
 * cdef int py_call_with_gil(lua_State* L, py_object *py_obj) with gil:             # <<<<<<<<<<<<<<
 *     cdef LuaRuntime runtime = None
 *     try:
 */

static  int __pyx_f_4lupa_5_lupa_py_call_with_gil(lua_State *__pyx_v_L, struct __pyx_t_4lupa_5_lupa_py_object *__pyx_v_py_obj) {
  struct __pyx_obj_4lupa_5_lupa_LuaRuntime *__pyx_v_runtime = 0;
  PyObject *__pyx_v_e;
  PyObject *__pyx_v_message;
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  char *__pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyGILState_STATE _save = PyGILState_Ensure();
  __Pyx_RefNannySetupContext("py_call_with_gil");
  __pyx_v_e = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_message = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":421
 * 
 * cdef int py_call_with_gil(lua_State* L, py_object *py_obj) with gil:
 *     cdef LuaRuntime runtime = None             # <<<<<<<<<<<<<<
 *     try:
 *         runtime = <LuaRuntime?>py_obj.runtime
 */
  __Pyx_INCREF(Py_None);
  __pyx_v_runtime = ((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)Py_None);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":422
 * cdef int py_call_with_gil(lua_State* L, py_object *py_obj) with gil:
 *     cdef LuaRuntime runtime = None
 *     try:             # <<<<<<<<<<<<<<
 *         runtime = <LuaRuntime?>py_obj.runtime
 *         if runtime._state is not L:
 */
  {
    PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
    __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
    __Pyx_XGOTREF(__pyx_save_exc_type);
    __Pyx_XGOTREF(__pyx_save_exc_value);
    __Pyx_XGOTREF(__pyx_save_exc_tb);
    /*try:*/ {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":423
 *     cdef LuaRuntime runtime = None
 *     try:
 *         runtime = <LuaRuntime?>py_obj.runtime             # <<<<<<<<<<<<<<
 *         if runtime._state is not L:
 *             lua.luaL_argerror(L, 1, "cannot mix objects from different Lua runtimes")
 */
      __Pyx_INCREF(((PyObject *)((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_py_obj->runtime)));
      __Pyx_DECREF(((PyObject *)__pyx_v_runtime));
      __pyx_v_runtime = ((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_py_obj->runtime);

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":424
 *     try:
 *         runtime = <LuaRuntime?>py_obj.runtime
 *         if runtime._state is not L:             # <<<<<<<<<<<<<<
 *             lua.luaL_argerror(L, 1, "cannot mix objects from different Lua runtimes")
 *             return 0
 */
      __pyx_t_1 = (__pyx_v_runtime->_state != __pyx_v_L);
      if (__pyx_t_1) {

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":425
 *         runtime = <LuaRuntime?>py_obj.runtime
 *         if runtime._state is not L:
 *             lua.luaL_argerror(L, 1, "cannot mix objects from different Lua runtimes")             # <<<<<<<<<<<<<<
 *             return 0
 *         return call_python(runtime, py_obj)
 */
        luaL_argerror(__pyx_v_L, 1, __pyx_k_13);

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":426
 *         if runtime._state is not L:
 *             lua.luaL_argerror(L, 1, "cannot mix objects from different Lua runtimes")
 *             return 0             # <<<<<<<<<<<<<<
 *         return call_python(runtime, py_obj)
 *     except Exception as e:
 */
        __pyx_r = 0;
        goto __pyx_L7_try_return;
        goto __pyx_L11;
      }
      __pyx_L11:;

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":427
 *             lua.luaL_argerror(L, 1, "cannot mix objects from different Lua runtimes")
 *             return 0
 *         return call_python(runtime, py_obj)             # <<<<<<<<<<<<<<
 *     except Exception as e:
 *         runtime.store_raised_exception()
 */
      __pyx_t_1 = __pyx_f_4lupa_5_lupa_call_python(__pyx_v_runtime, __pyx_v_py_obj); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 427; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __pyx_r = __pyx_t_1;
      goto __pyx_L7_try_return;
    }
    __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
    __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
    __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
    goto __pyx_L10_try_end;
    __pyx_L7_try_return:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    goto __pyx_L0;
    __pyx_L3_error:;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":428
 *             return 0
 *         return call_python(runtime, py_obj)
 *     except Exception as e:             # <<<<<<<<<<<<<<
 *         runtime.store_raised_exception()
 *         try:
 */
    __pyx_t_2 = PyErr_ExceptionMatches(__pyx_builtin_Exception);
    if (__pyx_t_2) {
      __Pyx_AddTraceback("lupa._lupa.py_call_with_gil");
      if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_v_e);
      __pyx_v_e = __pyx_t_4;

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":429
 *         return call_python(runtime, py_obj)
 *     except Exception as e:
 *         runtime.store_raised_exception()             # <<<<<<<<<<<<<<
 *         try:
 *             message = (u"error during Python call: %r" % e).encode('UTF-8')
 */
      __pyx_t_2 = ((struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime *)__pyx_v_runtime->__pyx_vtab)->store_raised_exception(__pyx_v_runtime); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;}

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":430
 *     except Exception as e:
 *         runtime.store_raised_exception()
 *         try:             # <<<<<<<<<<<<<<
 *             message = (u"error during Python call: %r" % e).encode('UTF-8')
 *             lua.luaL_error(L, message)
 */
      {
        PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
        __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
        __Pyx_XGOTREF(__pyx_save_exc_type);
        __Pyx_XGOTREF(__pyx_save_exc_value);
        __Pyx_XGOTREF(__pyx_save_exc_tb);
        /*try:*/ {

          /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":431
 *         runtime.store_raised_exception()
 *         try:
 *             message = (u"error during Python call: %r" % e).encode('UTF-8')             # <<<<<<<<<<<<<<
 *             lua.luaL_error(L, message)
 *         except:
 */
          __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_23), __pyx_v_e); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L14_error;}
          __Pyx_GOTREF(((PyObject *)__pyx_t_6));
          if (unlikely(__pyx_t_6 == Py_None)) {
            PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'encode'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L14_error;} 
          }
          __pyx_t_7 = ((PyObject *)PyUnicode_AsUTF8String(__pyx_t_6)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L14_error;}
          __Pyx_GOTREF(((PyObject *)__pyx_t_7));
          __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_v_message);
          __pyx_v_message = ((PyObject *)__pyx_t_7);
          __pyx_t_7 = 0;

          /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":432
 *         try:
 *             message = (u"error during Python call: %r" % e).encode('UTF-8')
 *             lua.luaL_error(L, message)             # <<<<<<<<<<<<<<
 *         except:
 *             lua.luaL_error(L, b"error during Python call")
 */
          __pyx_t_8 = PyBytes_AsString(__pyx_v_message); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L14_error;}
          luaL_error(__pyx_v_L, __pyx_t_8);
        }
        __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
        __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
        __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
        goto __pyx_L21_try_end;
        __pyx_L14_error:;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":433
 *             message = (u"error during Python call: %r" % e).encode('UTF-8')
 *             lua.luaL_error(L, message)
 *         except:             # <<<<<<<<<<<<<<
 *             lua.luaL_error(L, b"error during Python call")
 *         return 0
 */
        /*except:*/ {
          __Pyx_AddTraceback("lupa._lupa.py_call_with_gil");
          if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_6, &__pyx_t_9) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __pyx_L16_except_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_GOTREF(__pyx_t_9);

          /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":434
 *             lua.luaL_error(L, message)
 *         except:
 *             lua.luaL_error(L, b"error during Python call")             # <<<<<<<<<<<<<<
 *         return 0
 * 
 */
          luaL_error(__pyx_v_L, __pyx_k_24);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          goto __pyx_L15_exception_handled;
        }
        __pyx_L16_except_error:;
        __Pyx_XGIVEREF(__pyx_save_exc_type);
        __Pyx_XGIVEREF(__pyx_save_exc_value);
        __Pyx_XGIVEREF(__pyx_save_exc_tb);
        __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
        goto __pyx_L5_except_error;
        __pyx_L15_exception_handled:;
        __Pyx_XGIVEREF(__pyx_save_exc_type);
        __Pyx_XGIVEREF(__pyx_save_exc_value);
        __Pyx_XGIVEREF(__pyx_save_exc_tb);
        __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
        __pyx_L21_try_end:;
      }

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":435
 *         except:
 *             lua.luaL_error(L, b"error during Python call")
 *         return 0             # <<<<<<<<<<<<<<
 * 
 * cdef int py_object_call(lua_State* L):
 */
      __pyx_r = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L6_except_return;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L4_exception_handled;
    }
    __pyx_L5_except_error:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    goto __pyx_L1_error;
    __pyx_L6_except_return:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    goto __pyx_L0;
    __pyx_L4_exception_handled:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    __pyx_L10_try_end:;
  }

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_WriteUnraisable("lupa._lupa.py_call_with_gil");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_runtime);
  __Pyx_DECREF(__pyx_v_e);
  __Pyx_DECREF(__pyx_v_message);
  __Pyx_RefNannyFinishContext();
  PyGILState_Release(_save);
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":437
 *         return 0
 * 
 * cdef int py_object_call(lua_State* L):             # <<<<<<<<<<<<<<
 *     cdef py_object *py_obj = <py_object*> lua.luaL_checkudata(L, 1, POBJECT)
 *     if not py_obj:
 */

static  int __pyx_f_4lupa_5_lupa_py_object_call(lua_State *__pyx_v_L) {
  struct __pyx_t_4lupa_5_lupa_py_object *__pyx_v_py_obj;
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("py_object_call");

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":438
 * 
 * cdef int py_object_call(lua_State* L):
 *     cdef py_object *py_obj = <py_object*> lua.luaL_checkudata(L, 1, POBJECT)             # <<<<<<<<<<<<<<
 *     if not py_obj:
 *         lua.luaL_argerror(L, 1, "not a python object")
 */
  __pyx_v_py_obj = ((struct __pyx_t_4lupa_5_lupa_py_object *)luaL_checkudata(__pyx_v_L, 1, __pyx_k__POBJECT));

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":439
 * cdef int py_object_call(lua_State* L):
 *     cdef py_object *py_obj = <py_object*> lua.luaL_checkudata(L, 1, POBJECT)
 *     if not py_obj:             # <<<<<<<<<<<<<<
 *         lua.luaL_argerror(L, 1, "not a python object")
 *         return 0
 */
  __pyx_t_1 = (!(__pyx_v_py_obj != 0));
  if (__pyx_t_1) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":440
 *     cdef py_object *py_obj = <py_object*> lua.luaL_checkudata(L, 1, POBJECT)
 *     if not py_obj:
 *         lua.luaL_argerror(L, 1, "not a python object")             # <<<<<<<<<<<<<<
 *         return 0
 * 
 */
    luaL_argerror(__pyx_v_L, 1, __pyx_k_21);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":441
 *     if not py_obj:
 *         lua.luaL_argerror(L, 1, "not a python object")
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     return py_call_with_gil(L, py_obj)
 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":443
 *         return 0
 * 
 *     return py_call_with_gil(L, py_obj)             # <<<<<<<<<<<<<<
 * 
 * # str() support for Python objects
 */
  __pyx_r = __pyx_f_4lupa_5_lupa_py_call_with_gil(__pyx_v_L, __pyx_v_py_obj);
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":447
 * # str() support for Python objects
 * 
 * cdef int py_str_with_gil(lua_State* L, py_object* py_obj) with gil:             # <<<<<<<<<<<<<<
 *     cdef LuaRuntime runtime
 *     try:
 */

static  int __pyx_f_4lupa_5_lupa_py_str_with_gil(lua_State *__pyx_v_L, struct __pyx_t_4lupa_5_lupa_py_object *__pyx_v_py_obj) {
  struct __pyx_obj_4lupa_5_lupa_LuaRuntime *__pyx_v_runtime;
  PyObject *__pyx_v_s;
  PyObject *__pyx_v_e;
  PyObject *__pyx_v_message;
  int __pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  char *__pyx_t_4;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyGILState_STATE _save = PyGILState_Ensure();
  __Pyx_RefNannySetupContext("py_str_with_gil");
  __pyx_v_runtime = ((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_s = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_e = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_message = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":449
 * cdef int py_str_with_gil(lua_State* L, py_object* py_obj) with gil:
 *     cdef LuaRuntime runtime
 *     try:             # <<<<<<<<<<<<<<
 *         runtime = <LuaRuntime?>py_obj.runtime
 *         if runtime._state is not L:
 */
  {
    PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
    __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
    __Pyx_XGOTREF(__pyx_save_exc_type);
    __Pyx_XGOTREF(__pyx_save_exc_value);
    __Pyx_XGOTREF(__pyx_save_exc_tb);
    /*try:*/ {

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":450
 *     cdef LuaRuntime runtime
 *     try:
 *         runtime = <LuaRuntime?>py_obj.runtime             # <<<<<<<<<<<<<<
 *         if runtime._state is not L:
 *             lua.luaL_argerror(L, 1, "cannot mix objects from different Lua runtimes")
 */
      __Pyx_INCREF(((PyObject *)((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_py_obj->runtime)));
      __Pyx_DECREF(((PyObject *)__pyx_v_runtime));
      __pyx_v_runtime = ((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)__pyx_v_py_obj->runtime);

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":451
 *     try:
 *         runtime = <LuaRuntime?>py_obj.runtime
 *         if runtime._state is not L:             # <<<<<<<<<<<<<<
 *             lua.luaL_argerror(L, 1, "cannot mix objects from different Lua runtimes")
 *             return 0
 */
      __pyx_t_1 = (__pyx_v_runtime->_state != __pyx_v_L);
      if (__pyx_t_1) {

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":452
 *         runtime = <LuaRuntime?>py_obj.runtime
 *         if runtime._state is not L:
 *             lua.luaL_argerror(L, 1, "cannot mix objects from different Lua runtimes")             # <<<<<<<<<<<<<<
 *             return 0
 *         s = str(<object>py_obj.obj)
 */
        luaL_argerror(__pyx_v_L, 1, __pyx_k_13);

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":453
 *         if runtime._state is not L:
 *             lua.luaL_argerror(L, 1, "cannot mix objects from different Lua runtimes")
 *             return 0             # <<<<<<<<<<<<<<
 *         s = str(<object>py_obj.obj)
 *         if isinstance(s, unicode):
 */
        __pyx_r = 0;
        goto __pyx_L7_try_return;
        goto __pyx_L11;
      }
      __pyx_L11:;

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":454
 *             lua.luaL_argerror(L, 1, "cannot mix objects from different Lua runtimes")
 *             return 0
 *         s = str(<object>py_obj.obj)             # <<<<<<<<<<<<<<
 *         if isinstance(s, unicode):
 *             s = (<unicode>s).encode('UTF-8')
 */
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(((PyObject *)__pyx_v_py_obj->obj));
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_py_obj->obj));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_py_obj->obj));
      __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)&PyString_Type)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_v_s);
      __pyx_v_s = __pyx_t_3;
      __pyx_t_3 = 0;

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":455
 *             return 0
 *         s = str(<object>py_obj.obj)
 *         if isinstance(s, unicode):             # <<<<<<<<<<<<<<
 *             s = (<unicode>s).encode('UTF-8')
 *         else:
 */
      __pyx_t_1 = PyObject_TypeCheck(__pyx_v_s, ((PyTypeObject *)((PyObject*)&PyUnicode_Type))); 
      if (__pyx_t_1) {

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":456
 *         s = str(<object>py_obj.obj)
 *         if isinstance(s, unicode):
 *             s = (<unicode>s).encode('UTF-8')             # <<<<<<<<<<<<<<
 *         else:
 *             assert isinstance(s, bytes)
 */
        if (unlikely(((PyObject *)__pyx_v_s) == Py_None)) {
          PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'encode'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L3_error;} 
        }
        __pyx_t_3 = ((PyObject *)PyUnicode_AsUTF8String(((PyObject *)__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_3));
        __Pyx_DECREF(__pyx_v_s);
        __pyx_v_s = ((PyObject *)__pyx_t_3);
        __pyx_t_3 = 0;
        goto __pyx_L12;
      }
      /*else*/ {

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":458
 *             s = (<unicode>s).encode('UTF-8')
 *         else:
 *             assert isinstance(s, bytes)             # <<<<<<<<<<<<<<
 *         lua.lua_pushlstring(L, <bytes>s, len(<bytes>s))
 *         return 1 # returning 1 value
 */
        #ifndef PYREX_WITHOUT_ASSERTIONS
        __pyx_t_1 = PyObject_TypeCheck(__pyx_v_s, ((PyTypeObject *)((PyObject*)&PyBytes_Type))); 
        if (unlikely(!__pyx_t_1)) {
          PyErr_SetNone(PyExc_AssertionError);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 458; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        #endif
      }
      __pyx_L12:;

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":459
 *         else:
 *             assert isinstance(s, bytes)
 *         lua.lua_pushlstring(L, <bytes>s, len(<bytes>s))             # <<<<<<<<<<<<<<
 *         return 1 # returning 1 value
 *     except Exception as e:
 */
      __pyx_t_4 = PyBytes_AsString(__pyx_v_s); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      if (unlikely(((PyObject *)__pyx_v_s) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L3_error;} 
      }
      __pyx_t_5 = PyBytes_GET_SIZE(((PyObject *)((PyObject *)__pyx_v_s))); 
      lua_pushlstring(__pyx_v_L, __pyx_t_4, __pyx_t_5);

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":460
 *             assert isinstance(s, bytes)
 *         lua.lua_pushlstring(L, <bytes>s, len(<bytes>s))
 *         return 1 # returning 1 value             # <<<<<<<<<<<<<<
 *     except Exception as e:
 *         runtime.store_raised_exception()
 */
      __pyx_r = 1;
      goto __pyx_L7_try_return;
    }
    __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
    __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
    __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
    goto __pyx_L10_try_end;
    __pyx_L7_try_return:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    goto __pyx_L0;
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":461
 *         lua.lua_pushlstring(L, <bytes>s, len(<bytes>s))
 *         return 1 # returning 1 value
 *     except Exception as e:             # <<<<<<<<<<<<<<
 *         runtime.store_raised_exception()
 *         try:
 */
    __pyx_t_6 = PyErr_ExceptionMatches(__pyx_builtin_Exception);
    if (__pyx_t_6) {
      __Pyx_AddTraceback("lupa._lupa.py_str_with_gil");
      if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_2, &__pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_v_e);
      __pyx_v_e = __pyx_t_2;

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":462
 *         return 1 # returning 1 value
 *     except Exception as e:
 *         runtime.store_raised_exception()             # <<<<<<<<<<<<<<
 *         try:
 *             message = (u"error during Python str() call: %r" % e).encode('UTF-8')
 */
      __pyx_t_6 = ((struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime *)__pyx_v_runtime->__pyx_vtab)->store_raised_exception(__pyx_v_runtime); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;}

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":463
 *     except Exception as e:
 *         runtime.store_raised_exception()
 *         try:             # <<<<<<<<<<<<<<
 *             message = (u"error during Python str() call: %r" % e).encode('UTF-8')
 *             lua.luaL_error(L, message)
 */
      {
        PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
        __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
        __Pyx_XGOTREF(__pyx_save_exc_type);
        __Pyx_XGOTREF(__pyx_save_exc_value);
        __Pyx_XGOTREF(__pyx_save_exc_tb);
        /*try:*/ {

          /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":464
 *         runtime.store_raised_exception()
 *         try:
 *             message = (u"error during Python str() call: %r" % e).encode('UTF-8')             # <<<<<<<<<<<<<<
 *             lua.luaL_error(L, message)
 *         except:
 */
          __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_25), __pyx_v_e); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 464; __pyx_clineno = __LINE__; goto __pyx_L15_error;}
          __Pyx_GOTREF(((PyObject *)__pyx_t_8));
          if (unlikely(__pyx_t_8 == Py_None)) {
            PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'encode'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 464; __pyx_clineno = __LINE__; goto __pyx_L15_error;} 
          }
          __pyx_t_9 = ((PyObject *)PyUnicode_AsUTF8String(__pyx_t_8)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 464; __pyx_clineno = __LINE__; goto __pyx_L15_error;}
          __Pyx_GOTREF(((PyObject *)__pyx_t_9));
          __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_v_message);
          __pyx_v_message = ((PyObject *)__pyx_t_9);
          __pyx_t_9 = 0;

          /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":465
 *         try:
 *             message = (u"error during Python str() call: %r" % e).encode('UTF-8')
 *             lua.luaL_error(L, message)             # <<<<<<<<<<<<<<
 *         except:
 *             lua.luaL_error(L, b"error during Python str() call")
 */
          __pyx_t_4 = PyBytes_AsString(__pyx_v_message); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 465; __pyx_clineno = __LINE__; goto __pyx_L15_error;}
          luaL_error(__pyx_v_L, __pyx_t_4);
        }
        __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
        __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
        __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
        goto __pyx_L22_try_end;
        __pyx_L15_error:;
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":466
 *             message = (u"error during Python str() call: %r" % e).encode('UTF-8')
 *             lua.luaL_error(L, message)
 *         except:             # <<<<<<<<<<<<<<
 *             lua.luaL_error(L, b"error during Python str() call")
 *         return 0
 */
        /*except:*/ {
          __Pyx_AddTraceback("lupa._lupa.py_str_with_gil");
          if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_8, &__pyx_t_10) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_GOTREF(__pyx_t_10);

          /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":467
 *             lua.luaL_error(L, message)
 *         except:
 *             lua.luaL_error(L, b"error during Python str() call")             # <<<<<<<<<<<<<<
 *         return 0
 * 
 */
          luaL_error(__pyx_v_L, __pyx_k_26);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          goto __pyx_L16_exception_handled;
        }
        __pyx_L17_except_error:;
        __Pyx_XGIVEREF(__pyx_save_exc_type);
        __Pyx_XGIVEREF(__pyx_save_exc_value);
        __Pyx_XGIVEREF(__pyx_save_exc_tb);
        __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
        goto __pyx_L5_except_error;
        __pyx_L16_exception_handled:;
        __Pyx_XGIVEREF(__pyx_save_exc_type);
        __Pyx_XGIVEREF(__pyx_save_exc_value);
        __Pyx_XGIVEREF(__pyx_save_exc_tb);
        __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
        __pyx_L22_try_end:;
      }

      /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":468
 *         except:
 *             lua.luaL_error(L, b"error during Python str() call")
 *         return 0             # <<<<<<<<<<<<<<
 * 
 * cdef int py_object_str(lua_State* L):
 */
      __pyx_r = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L6_except_return;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L4_exception_handled;
    }
    __pyx_L5_except_error:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    goto __pyx_L1_error;
    __pyx_L6_except_return:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    goto __pyx_L0;
    __pyx_L4_exception_handled:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    __pyx_L10_try_end:;
  }

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_WriteUnraisable("lupa._lupa.py_str_with_gil");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_runtime);
  __Pyx_DECREF(__pyx_v_s);
  __Pyx_DECREF(__pyx_v_e);
  __Pyx_DECREF(__pyx_v_message);
  __Pyx_RefNannyFinishContext();
  PyGILState_Release(_save);
  return __pyx_r;
}

/* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":470
 *         return 0
 * 
 * cdef int py_object_str(lua_State* L):             # <<<<<<<<<<<<<<
 *     cdef py_object *py_obj = <py_object*> lua.luaL_checkudata(L, 1, POBJECT)
 *     if not py_obj:
 */

static  int __pyx_f_4lupa_5_lupa_py_object_str(lua_State *__pyx_v_L) {
  struct __pyx_t_4lupa_5_lupa_py_object *__pyx_v_py_obj;
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("py_object_str");

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":471
 * 
 * cdef int py_object_str(lua_State* L):
 *     cdef py_object *py_obj = <py_object*> lua.luaL_checkudata(L, 1, POBJECT)             # <<<<<<<<<<<<<<
 *     if not py_obj:
 *         lua.luaL_argerror(L, 1, "not a python object")
 */
  __pyx_v_py_obj = ((struct __pyx_t_4lupa_5_lupa_py_object *)luaL_checkudata(__pyx_v_L, 1, __pyx_k__POBJECT));

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":472
 * cdef int py_object_str(lua_State* L):
 *     cdef py_object *py_obj = <py_object*> lua.luaL_checkudata(L, 1, POBJECT)
 *     if not py_obj:             # <<<<<<<<<<<<<<
 *         lua.luaL_argerror(L, 1, "not a python object")
 *         return 0
 */
  __pyx_t_1 = (!(__pyx_v_py_obj != 0));
  if (__pyx_t_1) {

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":473
 *     cdef py_object *py_obj = <py_object*> lua.luaL_checkudata(L, 1, POBJECT)
 *     if not py_obj:
 *         lua.luaL_argerror(L, 1, "not a python object")             # <<<<<<<<<<<<<<
 *         return 0
 *     return py_str_with_gil(L, py_obj)
 */
    luaL_argerror(__pyx_v_L, 1, __pyx_k_21);

    /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":474
 *     if not py_obj:
 *         lua.luaL_argerror(L, 1, "not a python object")
 *         return 0             # <<<<<<<<<<<<<<
 *     return py_str_with_gil(L, py_obj)
 * 
 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":475
 *         lua.luaL_argerror(L, 1, "not a python object")
 *         return 0
 *     return py_str_with_gil(L, py_obj)             # <<<<<<<<<<<<<<
 * 
 * # special methods for Lua
 */
  __pyx_r = __pyx_f_4lupa_5_lupa_py_str_with_gil(__pyx_v_L, __pyx_v_py_obj);
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_tp_new_4lupa_5_lupa__LuaObject(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_4lupa_5_lupa__LuaObject *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_4lupa_5_lupa__LuaObject *)o);
  p->_runtime = ((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)Py_None); Py_INCREF(Py_None);
  if (__pyx_pf_4lupa_5_lupa_10_LuaObject___cinit__(o, __pyx_empty_tuple, NULL) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_4lupa_5_lupa__LuaObject(PyObject *o) {
  struct __pyx_obj_4lupa_5_lupa__LuaObject *p = (struct __pyx_obj_4lupa_5_lupa__LuaObject *)o;
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pf_4lupa_5_lupa_10_LuaObject___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_XDECREF(((PyObject *)p->_runtime));
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_4lupa_5_lupa__LuaObject(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_4lupa_5_lupa__LuaObject *p = (struct __pyx_obj_4lupa_5_lupa__LuaObject *)o;
  if (p->_runtime) {
    e = (*v)(((PyObject*)p->_runtime), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_4lupa_5_lupa__LuaObject(PyObject *o) {
  struct __pyx_obj_4lupa_5_lupa__LuaObject *p = (struct __pyx_obj_4lupa_5_lupa__LuaObject *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->_runtime);
  p->_runtime = ((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_tp_getattro_4lupa_5_lupa__LuaObject(PyObject *o, PyObject *n) {
  PyObject *v = PyObject_GenericGetAttr(o, n);
  if (!v && PyErr_ExceptionMatches(PyExc_AttributeError)) {
    PyErr_Clear();
    v = __pyx_pf_4lupa_5_lupa_10_LuaObject___getattr__(o, n);
  }
  return v;
}

static PyMethodDef __pyx_methods_4lupa_5_lupa__LuaObject[] = {
  {__Pyx_NAMESTR("__call__"), (PyCFunction)__pyx_pf_4lupa_5_lupa_10_LuaObject___call__, METH_VARARGS|METH_KEYWORDS|METH_COEXIST, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("__str__"), (PyCFunction)__pyx_pf_4lupa_5_lupa_10_LuaObject___str__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("__getattr__"), (PyCFunction)__pyx_pf_4lupa_5_lupa_10_LuaObject___getattr__, METH_O|METH_COEXIST, __Pyx_DOCSTR(0)},
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number__LuaObject = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION >= 3
  0, /*reserved*/
  #else
  0, /*nb_long*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX)
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence__LuaObject = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping__LuaObject = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer__LuaObject = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_4lupa_5_lupa__LuaObject = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("lupa._lupa._LuaObject"), /*tp_name*/
  sizeof(struct __pyx_obj_4lupa_5_lupa__LuaObject), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_4lupa_5_lupa__LuaObject, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION >= 3
  0, /*reserved*/
  #else
  0, /*tp_compare*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number__LuaObject, /*tp_as_number*/
  &__pyx_tp_as_sequence__LuaObject, /*tp_as_sequence*/
  &__pyx_tp_as_mapping__LuaObject, /*tp_as_mapping*/
  0, /*tp_hash*/
  __pyx_pf_4lupa_5_lupa_10_LuaObject___call__, /*tp_call*/
  __pyx_pf_4lupa_5_lupa_10_LuaObject___str__, /*tp_str*/
  __pyx_tp_getattro_4lupa_5_lupa__LuaObject, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer__LuaObject, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_4lupa_5_lupa__LuaObject, /*tp_traverse*/
  __pyx_tp_clear_4lupa_5_lupa__LuaObject, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_4lupa_5_lupa__LuaObject, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_4lupa_5_lupa_10_LuaObject___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_4lupa_5_lupa__LuaObject, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};
static struct __pyx_vtabstruct_4lupa_5_lupa_LuaRuntime __pyx_vtable_4lupa_5_lupa_LuaRuntime;

static PyObject *__pyx_tp_new_4lupa_5_lupa_LuaRuntime(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_4lupa_5_lupa_LuaRuntime *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)o);
  p->__pyx_vtab = __pyx_vtabptr_4lupa_5_lupa_LuaRuntime;
  p->_raised_exception = ((PyObject *)Py_None); Py_INCREF(Py_None);
  if (__pyx_pf_4lupa_5_lupa_10LuaRuntime___cinit__(o, __pyx_empty_tuple, NULL) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_4lupa_5_lupa_LuaRuntime(PyObject *o) {
  struct __pyx_obj_4lupa_5_lupa_LuaRuntime *p = (struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)o;
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pf_4lupa_5_lupa_10LuaRuntime___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_XDECREF(((PyObject *)p->_raised_exception));
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_4lupa_5_lupa_LuaRuntime(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_4lupa_5_lupa_LuaRuntime *p = (struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)o;
  if (p->_raised_exception) {
    e = (*v)(p->_raised_exception, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_4lupa_5_lupa_LuaRuntime(PyObject *o) {
  struct __pyx_obj_4lupa_5_lupa_LuaRuntime *p = (struct __pyx_obj_4lupa_5_lupa_LuaRuntime *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->_raised_exception);
  p->_raised_exception = ((PyObject *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_4lupa_5_lupa_LuaRuntime[] = {
  {__Pyx_NAMESTR("eval"), (PyCFunction)__pyx_pf_4lupa_5_lupa_10LuaRuntime_eval, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("run"), (PyCFunction)__pyx_pf_4lupa_5_lupa_10LuaRuntime_run, METH_O, __Pyx_DOCSTR(0)},
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_LuaRuntime = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION >= 3
  0, /*reserved*/
  #else
  0, /*nb_long*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX)
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_LuaRuntime = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_LuaRuntime = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_LuaRuntime = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_4lupa_5_lupa_LuaRuntime = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("lupa._lupa.LuaRuntime"), /*tp_name*/
  sizeof(struct __pyx_obj_4lupa_5_lupa_LuaRuntime), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_4lupa_5_lupa_LuaRuntime, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION >= 3
  0, /*reserved*/
  #else
  0, /*tp_compare*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number_LuaRuntime, /*tp_as_number*/
  &__pyx_tp_as_sequence_LuaRuntime, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_LuaRuntime, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_LuaRuntime, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("The main entry point to the Lua runtime.\n\n    Example usage::\n\n      >>> from lupa import LuaRuntime\n      >>> lua = LuaRuntime()\n\n      >>> lua.eval('1+1')\n      2\n\n      >>> def add1(n): return n+1\n      >>> func = lua.eval('function(f, n) return f(n) end')\n      >>> func(add1, 2)\n      3\n    "), /*tp_doc*/
  __pyx_tp_traverse_4lupa_5_lupa_LuaRuntime, /*tp_traverse*/
  __pyx_tp_clear_4lupa_5_lupa_LuaRuntime, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_4lupa_5_lupa_LuaRuntime, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_4lupa_5_lupa_LuaRuntime, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

static void __pyx_init_filenames(void); /*proto*/

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    __Pyx_NAMESTR("_lupa"),
    0, /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
  {&__pyx_kp_s_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 1, 0},
  {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0},
  {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0},
  {&__pyx_kp_s_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 1, 0},
  {&__pyx_n_s_17, __pyx_k_17, sizeof(__pyx_k_17), 0, 0, 1, 1},
  {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0},
  {&__pyx_kp_s_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 1, 0},
  {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0},
  {&__pyx_kp_s_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 0, 1, 0},
  {&__pyx_n_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 1},
  {&__pyx_kp_u_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 1, 0, 0},
  {&__pyx_kp_u_25, __pyx_k_25, sizeof(__pyx_k_25), 0, 1, 0, 0},
  {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0},
  {&__pyx_kp_b_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 0, 0},
  {&__pyx_kp_b_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 0, 0},
  {&__pyx_kp_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 0},
  {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0},
  {&__pyx_n_s__ASCII, __pyx_k__ASCII, sizeof(__pyx_k__ASCII), 0, 0, 1, 1},
  {&__pyx_n_s__Exception, __pyx_k__Exception, sizeof(__pyx_k__Exception), 0, 0, 1, 1},
  {&__pyx_n_s__LuaError, __pyx_k__LuaError, sizeof(__pyx_k__LuaError), 0, 0, 1, 1},
  {&__pyx_n_s__LuaRuntime, __pyx_k__LuaRuntime, sizeof(__pyx_k__LuaRuntime), 0, 0, 1, 1},
  {&__pyx_n_s__Py_None, __pyx_k__Py_None, sizeof(__pyx_k__Py_None), 0, 0, 1, 1},
  {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1},
  {&__pyx_n_s__UnicodeDecodeError, __pyx_k__UnicodeDecodeError, sizeof(__pyx_k__UnicodeDecodeError), 0, 0, 1, 1},
  {&__pyx_n_s____all__, __pyx_k____all__, sizeof(__pyx_k____all__), 0, 0, 1, 1},
  {&__pyx_n_s____call__, __pyx_k____call__, sizeof(__pyx_k____call__), 0, 0, 1, 1},
  {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
  {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
  {&__pyx_n_s___raised_exception, __pyx_k___raised_exception, sizeof(__pyx_k___raised_exception), 0, 0, 1, 1},
  {&__pyx_n_s___ref, __pyx_k___ref, sizeof(__pyx_k___ref), 0, 0, 1, 1},
  {&__pyx_n_s___refiter, __pyx_k___refiter, sizeof(__pyx_k___refiter), 0, 0, 1, 1},
  {&__pyx_n_s___runtime, __pyx_k___runtime, sizeof(__pyx_k___runtime), 0, 0, 1, 1},
  {&__pyx_n_s___state, __pyx_k___state, sizeof(__pyx_k___state), 0, 0, 1, 1},
  {&__pyx_n_s___thread_lock, __pyx_k___thread_lock, sizeof(__pyx_k___thread_lock), 0, 0, 1, 1},
  {&__pyx_n_s__as_index, __pyx_k__as_index, sizeof(__pyx_k__as_index), 0, 0, 1, 1},
  {&__pyx_n_s__decode, __pyx_k__decode, sizeof(__pyx_k__decode), 0, 0, 1, 1},
  {&__pyx_n_s__encode, __pyx_k__encode, sizeof(__pyx_k__encode), 0, 0, 1, 1},
  {&__pyx_n_s__enumerate, __pyx_k__enumerate, sizeof(__pyx_k__enumerate), 0, 0, 1, 1},
  {&__pyx_n_s__eval, __pyx_k__eval, sizeof(__pyx_k__eval), 0, 0, 1, 1},
  {&__pyx_n_s__exc_info, __pyx_k__exc_info, sizeof(__pyx_k__exc_info), 0, 0, 1, 1},
  {&__pyx_n_s__func, __pyx_k__func, sizeof(__pyx_k__func), 0, 0, 1, 1},
  {&__pyx_n_s__init_python_lib, __pyx_k__init_python_lib, sizeof(__pyx_k__init_python_lib), 0, 0, 1, 1},
  {&__pyx_n_s__lock, __pyx_k__lock, sizeof(__pyx_k__lock), 0, 0, 1, 1},
  {&__pyx_n_s__name, __pyx_k__name, sizeof(__pyx_k__name), 0, 0, 1, 1},
  {&__pyx_n_s__none, __pyx_k__none, sizeof(__pyx_k__none), 0, 0, 1, 1},
  {&__pyx_n_s__obj, __pyx_k__obj, sizeof(__pyx_k__obj), 0, 0, 1, 1},
  {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1},
  {&__pyx_n_s__register_py_object, __pyx_k__register_py_object, sizeof(__pyx_k__register_py_object), 0, 0, 1, 1},
  {&__pyx_n_s__runtime, __pyx_k__runtime, sizeof(__pyx_k__runtime), 0, 0, 1, 1},
  {&__pyx_n_s__sys, __pyx_k__sys, sizeof(__pyx_k__sys), 0, 0, 1, 1},
  {&__pyx_n_s__unlock, __pyx_k__unlock, sizeof(__pyx_k__unlock), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_Exception = __Pyx_GetName(__pyx_b, __pyx_n_s__Exception); if (!__pyx_builtin_Exception) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_eval = __Pyx_GetName(__pyx_b, __pyx_n_s__eval); if (!__pyx_builtin_eval) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_UnicodeDecodeError = __Pyx_GetName(__pyx_b, __pyx_n_s__UnicodeDecodeError); if (!__pyx_builtin_UnicodeDecodeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitGlobals(void) {
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC init_lupa(void); /*proto*/
PyMODINIT_FUNC init_lupa(void)
#else
PyMODINIT_FUNC PyInit__lupa(void); /*proto*/
PyMODINIT_FUNC PyInit__lupa(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  luaL_Reg __pyx_t_4;
  #if CYTHON_REFNANNY
  void* __pyx_refnanny = NULL;
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  if (!__Pyx_RefNanny) {
      PyErr_Clear();
      __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
      if (!__Pyx_RefNanny)
          Py_FatalError("failed to import 'refnanny' module");
  }
  __pyx_refnanny = __Pyx_RefNanny->SetupContext("PyMODINIT_FUNC PyInit__lupa(void)", __LINE__, __FILE__);
  #endif
  __pyx_init_filenames();
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4(__Pyx_NAMESTR("_lupa"), __pyx_methods, 0, 0, PYTHON_API_VERSION);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  #if PY_MAJOR_VERSION < 3
  Py_INCREF(__pyx_m);
  #endif
  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_module_is_main_lupa___lupa) {
    if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Global init code ---*/
  __pyx_v_4lupa_5_lupa_exc_info = Py_None; Py_INCREF(Py_None);
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  if (PyType_Ready(&__pyx_type_4lupa_5_lupa__LuaObject) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "_LuaObject", (PyObject *)&__pyx_type_4lupa_5_lupa__LuaObject) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_4lupa_5_lupa__LuaObject = &__pyx_type_4lupa_5_lupa__LuaObject;
  __pyx_vtabptr_4lupa_5_lupa_LuaRuntime = &__pyx_vtable_4lupa_5_lupa_LuaRuntime;
  #if PY_MAJOR_VERSION >= 3
  __pyx_vtable_4lupa_5_lupa_LuaRuntime.lock = (int (*)(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *))__pyx_f_4lupa_5_lupa_10LuaRuntime_lock;
  __pyx_vtable_4lupa_5_lupa_LuaRuntime.unlock = (void (*)(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *))__pyx_f_4lupa_5_lupa_10LuaRuntime_unlock;
  __pyx_vtable_4lupa_5_lupa_LuaRuntime.reraise_on_exception = (int (*)(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *))__pyx_f_4lupa_5_lupa_10LuaRuntime_reraise_on_exception;
  __pyx_vtable_4lupa_5_lupa_LuaRuntime.store_raised_exception = (int (*)(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *))__pyx_f_4lupa_5_lupa_10LuaRuntime_store_raised_exception;
  __pyx_vtable_4lupa_5_lupa_LuaRuntime.register_py_object = (int (*)(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *, PyObject *, PyObject *, PyObject *))__pyx_f_4lupa_5_lupa_10LuaRuntime_register_py_object;
  __pyx_vtable_4lupa_5_lupa_LuaRuntime.init_python_lib = (int (*)(struct __pyx_obj_4lupa_5_lupa_LuaRuntime *))__pyx_f_4lupa_5_lupa_10LuaRuntime_init_python_lib;
  #else
  *(void(**)(void))&__pyx_vtable_4lupa_5_lupa_LuaRuntime.lock = (void(*)(void))__pyx_f_4lupa_5_lupa_10LuaRuntime_lock;
  *(void(**)(void))&__pyx_vtable_4lupa_5_lupa_LuaRuntime.unlock = (void(*)(void))__pyx_f_4lupa_5_lupa_10LuaRuntime_unlock;
  *(void(**)(void))&__pyx_vtable_4lupa_5_lupa_LuaRuntime.reraise_on_exception = (void(*)(void))__pyx_f_4lupa_5_lupa_10LuaRuntime_reraise_on_exception;
  *(void(**)(void))&__pyx_vtable_4lupa_5_lupa_LuaRuntime.store_raised_exception = (void(*)(void))__pyx_f_4lupa_5_lupa_10LuaRuntime_store_raised_exception;
  *(void(**)(void))&__pyx_vtable_4lupa_5_lupa_LuaRuntime.register_py_object = (void(*)(void))__pyx_f_4lupa_5_lupa_10LuaRuntime_register_py_object;
  *(void(**)(void))&__pyx_vtable_4lupa_5_lupa_LuaRuntime.init_python_lib = (void(*)(void))__pyx_f_4lupa_5_lupa_10LuaRuntime_init_python_lib;
  #endif
  if (PyType_Ready(&__pyx_type_4lupa_5_lupa_LuaRuntime) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetVtable(__pyx_type_4lupa_5_lupa_LuaRuntime.tp_dict, __pyx_vtabptr_4lupa_5_lupa_LuaRuntime) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "LuaRuntime", (PyObject *)&__pyx_type_4lupa_5_lupa_LuaRuntime) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_4lupa_5_lupa_LuaRuntime = &__pyx_type_4lupa_5_lupa_LuaRuntime;
  /*--- Type import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":12
 * 
 * cdef object exc_info
 * from sys import exc_info             # <<<<<<<<<<<<<<
 * 
 * __all__ = ['LuaRuntime', 'LuaError']
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__exc_info));
  PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__exc_info));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__exc_info));
  __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__sys), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__exc_info); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_4lupa_5_lupa_exc_info);
  __Pyx_DECREF(__pyx_v_4lupa_5_lupa_exc_info);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_v_4lupa_5_lupa_exc_info = __pyx_t_1;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":14
 * from sys import exc_info
 * 
 * __all__ = ['LuaRuntime', 'LuaError']             # <<<<<<<<<<<<<<
 * 
 * DEF POBJECT = "POBJECT" # as used by LunaticPython
 */
  __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__LuaRuntime));
  PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_n_s__LuaRuntime));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__LuaRuntime));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__LuaError));
  PyList_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__LuaError));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__LuaError));
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____all__, ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":29
 * 
 * # empty for now
 * py_lib[0].name = NULL             # <<<<<<<<<<<<<<
 * py_lib[0].func = NULL
 * 
 */
  (__pyx_v_4lupa_5_lupa_py_lib[0]).name = NULL;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":30
 * # empty for now
 * py_lib[0].name = NULL
 * py_lib[0].func = NULL             # <<<<<<<<<<<<<<
 * 
 * 
 */
  (__pyx_v_4lupa_5_lupa_py_lib[0]).func = NULL;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":33
 * 
 * 
 * class LuaError(Exception):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_builtin_Exception);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_builtin_Exception);
  __Pyx_GIVEREF(__pyx_builtin_Exception);
  __pyx_t_3 = __Pyx_CreateClass(__pyx_t_1, ((PyObject *)__pyx_t_2), __pyx_n_s__LuaError, "lupa._lupa"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__LuaError, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":479
 * # special methods for Lua
 * 
 * py_object_lib[0] = lua.luaL_Reg(name = "__gc",       func = <lua.lua_CFunction> py_object_gc)             # <<<<<<<<<<<<<<
 * py_object_lib[1] = lua.luaL_Reg(name = "__call",     func = <lua.lua_CFunction> py_object_call)
 * py_object_lib[2] = lua.luaL_Reg(name = "__tostring", func = <lua.lua_CFunction> py_object_str)
 */
  __pyx_t_4.name = __pyx_k____gc;
  __pyx_t_4.func = ((lua_CFunction)__pyx_f_4lupa_5_lupa_py_object_gc);
  (__pyx_v_4lupa_5_lupa_py_object_lib[0]) = __pyx_t_4;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":480
 * 
 * py_object_lib[0] = lua.luaL_Reg(name = "__gc",       func = <lua.lua_CFunction> py_object_gc)
 * py_object_lib[1] = lua.luaL_Reg(name = "__call",     func = <lua.lua_CFunction> py_object_call)             # <<<<<<<<<<<<<<
 * py_object_lib[2] = lua.luaL_Reg(name = "__tostring", func = <lua.lua_CFunction> py_object_str)
 * py_object_lib[3] = lua.luaL_Reg(name = NULL, func = NULL)
 */
  __pyx_t_4.name = __pyx_k____call;
  __pyx_t_4.func = ((lua_CFunction)__pyx_f_4lupa_5_lupa_py_object_call);
  (__pyx_v_4lupa_5_lupa_py_object_lib[1]) = __pyx_t_4;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":481
 * py_object_lib[0] = lua.luaL_Reg(name = "__gc",       func = <lua.lua_CFunction> py_object_gc)
 * py_object_lib[1] = lua.luaL_Reg(name = "__call",     func = <lua.lua_CFunction> py_object_call)
 * py_object_lib[2] = lua.luaL_Reg(name = "__tostring", func = <lua.lua_CFunction> py_object_str)             # <<<<<<<<<<<<<<
 * py_object_lib[3] = lua.luaL_Reg(name = NULL, func = NULL)
 * 
 */
  __pyx_t_4.name = __pyx_k____tostring;
  __pyx_t_4.func = ((lua_CFunction)__pyx_f_4lupa_5_lupa_py_object_str);
  (__pyx_v_4lupa_5_lupa_py_object_lib[2]) = __pyx_t_4;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":482
 * py_object_lib[1] = lua.luaL_Reg(name = "__call",     func = <lua.lua_CFunction> py_object_call)
 * py_object_lib[2] = lua.luaL_Reg(name = "__tostring", func = <lua.lua_CFunction> py_object_str)
 * py_object_lib[3] = lua.luaL_Reg(name = NULL, func = NULL)             # <<<<<<<<<<<<<<
 * 
 * ## static const luaL_reg py_object_lib[] = {
 */
  __pyx_t_4.name = NULL;
  __pyx_t_4.func = NULL;
  (__pyx_v_4lupa_5_lupa_py_object_lib[3]) = __pyx_t_4;

  /* "/home/sbehnel/source/Python/lua/lupa/lupa/_lupa.pyx":2
 * 
 * cimport lua             # <<<<<<<<<<<<<<
 * from lua cimport lua_State
 * 
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;

  /* "/home/sbehnel/source/Python/cython/cython-work/Cython/Includes/cpython/iterator.pxd":1
 * cdef extern from "Python.h":             # <<<<<<<<<<<<<<
 * 
 *     ############################################################################
 */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  if (__pyx_m) {
    __Pyx_AddTraceback("init lupa._lupa");
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init lupa._lupa");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

static const char *__pyx_filenames[] = {
  "_lupa.pyx",
};

/* Runtime support code */

static void __pyx_init_filenames(void) {
  __pyx_f = __pyx_filenames;
}

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
    PyObject *result;
    result = PyObject_GetAttr(dict, name);
    if (!result)
        PyErr_SetObject(PyExc_NameError, name);
    return result;
}

static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *number, *more_or_less;

    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    number = (num_expected == 1) ? "" : "s";
    PyErr_Format(PyExc_TypeError,
        #if PY_VERSION_HEX < 0x02050000
            "%s() takes %s %d positional argument%s (%d given)",
        #else
            "%s() takes %s %zd positional argument%s (%zd given)",
        #endif
        func_name, more_or_less, num_expected, number, num_found);
}

static CYTHON_INLINE int __Pyx_CheckKeywordStrings(
    PyObject *kwdict,
    const char* function_name,
    int kw_allowed)
{
    PyObject* key = 0;
    Py_ssize_t pos = 0;
    while (PyDict_Next(kwdict, &pos, &key, 0)) {
        #if PY_MAJOR_VERSION < 3
        if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key)))
        #else
        if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key)))
        #endif
            goto invalid_keyword_type;
    }
    if ((!kw_allowed) && unlikely(key))
        goto invalid_keyword;
    return 1;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%s() keywords must be strings", function_name);
    return 0;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
    return 0;
}


static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_Format(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(PyObject_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();

    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}

static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;

    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}


static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *local_type, *local_value, *local_tb;
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
    if (unlikely(tstate->curexc_type))
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
        goto bad;
    #endif
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
    Py_INCREF(local_type);
    Py_INCREF(local_value);
    Py_INCREF(local_tb);
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    /* Make sure tstate is in a consistent state when we XDECREF
       these objects (XDECREF may run arbitrary code). */
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}


static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) {
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
}

static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
    PyObject *py_import = 0;
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    py_import = __Pyx_GetAttrString(__pyx_b, "__import__");
    if (!py_import)
        goto bad;
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    module = PyObject_CallFunctionObjArgs(py_import,
        name, global_dict, empty_dict, list, NULL);
bad:
    Py_XDECREF(empty_list);
    Py_XDECREF(py_import);
    Py_XDECREF(empty_dict);
    return module;
}

static PyObject *__Pyx_CreateClass(
    PyObject *bases, PyObject *dict, PyObject *name, const char *modname)
{
    PyObject *py_modname;
    PyObject *result = 0;

    #if PY_MAJOR_VERSION < 3
    py_modname = PyString_FromString(modname);
    #else
    py_modname = PyUnicode_FromString(modname);
    #endif
    if (!py_modname)
        goto bad;
    if (PyDict_SetItemString(dict, "__module__", py_modname) < 0)
        goto bad;
    #if PY_MAJOR_VERSION < 3
    result = PyClass_New(bases, dict, name);
    #else
    result = PyObject_CallFunctionObjArgs((PyObject *)&PyType_Type, name, bases, dict, NULL);
    #endif
bad:
    Py_XDECREF(py_modname);
    return result;
}

#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    Py_XINCREF(type);
    Py_XINCREF(value);
    Py_XINCREF(tb);
    /* First, check the traceback argument, replacing None with NULL. */
    if (tb == Py_None) {
        Py_DECREF(tb);
        tb = 0;
    }
    else if (tb != NULL && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto raise_error;
    }
    /* Next, replace a missing value with None */
    if (value == NULL) {
        value = Py_None;
        Py_INCREF(value);
    }
    #if PY_VERSION_HEX < 0x02050000
    if (!PyClass_Check(type))
    #else
    if (!PyType_Check(type))
    #endif
    {
        /* Raising an instance.  The value should be a dummy. */
        if (value != Py_None) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        /* Normalize to raise <class>, <instance> */
        Py_DECREF(value);
        value = type;
        #if PY_VERSION_HEX < 0x02050000
            if (PyInstance_Check(type)) {
                type = (PyObject*) ((PyInstanceObject*)type)->in_class;
                Py_INCREF(type);
            }
            else {
                type = 0;
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception must be an old-style class or instance");
                goto raise_error;
            }
        #else
            type = (PyObject*) Py_TYPE(type);
            Py_INCREF(type);
            if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception class must be a subclass of BaseException");
                goto raise_error;
            }
        #endif
    }

    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}

#else /* Python 3+ */

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;

    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (!PyExceptionClass_Check(type)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }

    PyErr_SetObject(type, value);

    if (tb) {
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
    }

bad:
    return;
}
#endif

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
    const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned char" :
                    "value too large to convert to unsigned char");
            }
            return (unsigned char)-1;
        }
        return (unsigned char)val;
    }
    return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
    const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned short" :
                    "value too large to convert to unsigned short");
            }
            return (unsigned short)-1;
        }
        return (unsigned short)val;
    }
    return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
    const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned int" :
                    "value too large to convert to unsigned int");
            }
            return (unsigned int)-1;
        }
        return (unsigned int)val;
    }
    return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
    const char neg_one = (char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to char" :
                    "value too large to convert to char");
            }
            return (char)-1;
        }
        return (char)val;
    }
    return (char)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
    const short neg_one = (short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to short" :
                    "value too large to convert to short");
            }
            return (short)-1;
        }
        return (short)val;
    }
    return (short)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
    const signed char neg_one = (signed char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed char" :
                    "value too large to convert to signed char");
            }
            return (signed char)-1;
        }
        return (signed char)val;
    }
    return (signed char)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
    const signed short neg_one = (signed short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed short" :
                    "value too large to convert to signed short");
            }
            return (signed short)-1;
        }
        return (signed short)val;
    }
    return (signed short)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
    const signed int neg_one = (signed int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed int" :
                    "value too large to convert to signed int");
            }
            return (signed int)-1;
        }
        return (signed int)val;
    }
    return (signed int)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
    const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return (unsigned long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned long");
                return (unsigned long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        unsigned long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned long)-1;
        val = __Pyx_PyInt_AsUnsignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
    const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return (unsigned PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned PY_LONG_LONG");
                return (unsigned PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        unsigned PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
    const long neg_one = (long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to long");
            return (long)-1;
        }
        return (long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to long");
                return (long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long)-1;
        val = __Pyx_PyInt_AsLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to PY_LONG_LONG");
            return (PY_LONG_LONG)-1;
        }
        return (PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to PY_LONG_LONG");
                return (PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
    const signed long neg_one = (signed long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed long");
            return (signed long)-1;
        }
        return (signed long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed long");
                return (signed long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        signed long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed long)-1;
        val = __Pyx_PyInt_AsSignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
    const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed PY_LONG_LONG");
            return (signed PY_LONG_LONG)-1;
        }
        return (signed PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed PY_LONG_LONG");
                return (signed PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        signed PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsSignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static void __Pyx_WriteUnraisable(const char *name) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
}

static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
#else
    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#endif
    if (!ob)
        goto bad;
    if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0)
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"

static void __Pyx_AddTraceback(const char *funcname) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyObject *py_globals = 0;
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;

    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(__pyx_filename);
    #else
    py_srcfile = PyUnicode_FromString(__pyx_filename);
    #endif
    if (!py_srcfile) goto bad;
    if (__pyx_clineno) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    py_code = PyCode_New(
        0,            /*int argcount,*/
        #if PY_MAJOR_VERSION >= 3
        0,            /*int kwonlyargcount,*/
        #endif
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple,  /*PyObject *consts,*/
        __pyx_empty_tuple,  /*PyObject *names,*/
        __pyx_empty_tuple,  /*PyObject *varnames,*/
        __pyx_empty_tuple,  /*PyObject *freevars,*/
        __pyx_empty_tuple,  /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        __pyx_lineno,   /*int firstlineno,*/
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    if (!py_code) goto bad;
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        py_globals,          /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = __pyx_lineno;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else  /* Python 3+ has unicode identifiers */
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

/* Type Conversion Functions */

static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}

static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_VERSION_HEX < 0x03000000
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return Py_INCREF(x), x;
  m = Py_TYPE(x)->tp_as_number;
#if PY_VERSION_HEX < 0x03000000
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_VERSION_HEX < 0x03000000
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%s__ returned non-%s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}

static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject* x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}

static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
#if PY_VERSION_HEX < 0x02050000
   if (ival <= LONG_MAX)
       return PyInt_FromLong((long)ival);
   else {
       unsigned char *bytes = (unsigned char *) &ival;
       int one = 1; int little = (int)*(unsigned char*)&one;
       return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
   }
#else
   return PyInt_FromSize_t(ival);
#endif
}

static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
   unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
   if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
       return (size_t)-1;
   } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
       PyErr_SetString(PyExc_OverflowError,
                       "value too large to convert to size_t");
       return (size_t)-1;
   }
   return (size_t)val;
}


#endif /* Py_PYTHON_H */
