diff --git a/.github/test.sh b/.github/test.sh index 8533ee0..ade953d 100644 --- a/.github/test.sh +++ b/.github/test.sh @@ -1,5 +1,5 @@ -mv bin/libpylua.so tests/pylua.so -mv bin/libpylua.so tests/pylua.pyd +cp bin/libpylua.so tests/pylua.so +cp bin/libpylua.so tests/pylua.pyd cd tests FILE=luaunit.lua @@ -19,25 +19,30 @@ printf "Running Lua Side Tests\n" printf "\nTest Case 1\n" if ! lua test0.lua; then echo "Error" + exit -1 fi printf "\nTest Case 2\n" if ! lua test1.lua; then + echo "Error" exit -1 fi printf "\nTest Case 3\n" if ! lua test2.lua; then + echo "Error" exit -1 fi printf "\nTest Case 4\n" if ! lua test3.lua; then + echo "Error" exit -1 fi printf "\nTest Case 5\n" if ! lua test4.lua; then + echo "Error" exit -1 fi @@ -46,6 +51,7 @@ printf "\n\nRunning Python Side Tests\n" printf "\nTest Case 1\n" if ! python3 testA.py; then + echo "Error" exit -1 fi diff --git a/CMakeLists.txt b/CMakeLists.txt index 7279ad6..1fb4492 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,6 @@ -cmake_minimum_required (VERSION 3.8) +cmake_minimum_required (VERSION 3.10) + +project(pylua) find_package(PkgConfig REQUIRED) @@ -13,7 +15,7 @@ add_library(pylua SHARED src/convert.c src/py_lua.c src/lua_py.c) target_include_directories(pylua PRIVATE "src/") target_include_directories(pylua PRIVATE ${PYTHON_INCLUDE_DIRS}) -target_link_libraries(pylua ${PYTHON_LIBRARIES}) +target_link_libraries(pylua python3) target_compile_options(pylua PRIVATE ${PYTHON_CFLAGS_OTHER}) target_link_libraries(pylua ${LUA_LIBRARIES}) diff --git a/src/lua_py.c b/src/lua_py.c index a3215ef..377e655 100644 --- a/src/lua_py.c +++ b/src/lua_py.c @@ -1,5 +1,6 @@ #include "lua_py.h" #include +#include #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) @@ -32,31 +33,7 @@ int luaopen_pylua(lua_State* L) Py_Initialize(); - wchar_t* path = Py_GetPath(); - - #if defined(_WIN32) - wchar_t new_path[800]; - if (!new_path) - { - exit(-1); - } - new_path[0] = L'.'; - new_path[1] = L';'; - new_path[2] = L'\0'; - #else - wchar_t new_path[800]; - if (!new_path) - { - exit(-1); - } - new_path[0] = L'.'; - new_path[1] = L':'; - new_path[2] = L'\0'; - #endif - - wcsncat(new_path, path, wcslen(path)); - - PySys_SetPath(new_path); + PySys_SetArgv(0, NULL); pPylua_Module = PyImport_ImportModule("pylua"); if (!pPylua_Module) @@ -182,7 +159,7 @@ int call_PyFunc(lua_State* L) LUA_MEMORY_ERROR(L); } -int iter_PyGenerator(lua_State* L) +int iter_PyGenerator(lua_State* L, int _a1, long _a2) { PyLua_PyIterator* py_iter = (PyLua_PyIterator*)lua_touserdata(L, lua_upvalueindex(1)); diff --git a/src/lua_py.h b/src/lua_py.h index b7d4b78..86e8769 100644 --- a/src/lua_py.h +++ b/src/lua_py.h @@ -98,7 +98,7 @@ static int raise_error(lua_State* L, const char* msg) if ((err_msg += snprintf(err_msg, err_max, "%s", traceback_msg)) < 0) { err_max *= 4; - err_msg = err_msg - _err_msg; + err_msg = (char*)(err_msg - _err_msg); char* tmp = realloc(_err_msg, err_max); if (tmp) @@ -125,7 +125,7 @@ static int raise_error(lua_State* L, const char* msg) PyObject* str_exc_value = PyObject_Repr(pExcValue); PyObject* pExcValueStr = PyUnicode_AsEncodedString(str_exc_value, "utf-8", "strict"); - const char* strExcValue = PyBytes_AS_STRING(pExcValueStr); + char* strExcValue = PyBytes_AS_STRING(pExcValueStr); char* err_name = malloc(EXCEPTION_STR_LEN); if (!err_name) @@ -143,7 +143,7 @@ static int raise_error(lua_State* L, const char* msg) if (snprintf(err_msg, err_max, "%s", err_name) < 0) { err_max *= 4; - err_msg = err_msg - _err_msg; + err_msg = (char*)(err_msg - _err_msg); char* tmp = realloc(_err_msg, err_max); if (tmp) @@ -216,7 +216,7 @@ static int binary_base_pyobj_wrapper(lua_State* L, binary_op func) // Python Wrapper functions int call_PyFunc(lua_State* L); -int iter_PyGenerator(lua_State* L); +int iter_PyGenerator(lua_State* L, int _a1, long _a2); static int get_PyObj(lua_State* L); static int set_PyObj(lua_State* L); static int str_PyObj(lua_State* L); diff --git a/src/py_lua.c b/src/py_lua.c index 57d1020..304f322 100644 --- a/src/py_lua.c +++ b/src/py_lua.c @@ -103,11 +103,11 @@ static PyTypeObject pLuaFunc_Type = { .tp_itemsize = 0, .tp_flags = Py_TPFLAGS_DEFAULT, .tp_new = &PyType_GenericNew, - .tp_init = &init_LuaFunc_Wrapper, - .tp_call = &call_LuaFunc, - .tp_iter = &iter_LuaCoroutine, - .tp_iternext = &next_LuaCoroutine, - .tp_finalize = &gc_LuaFunc, + .tp_init = (initproc)init_LuaFunc_Wrapper, + .tp_call = (ternaryfunc)call_LuaFunc, + .tp_iter = (getiterfunc)iter_LuaCoroutine, + .tp_iternext = (iternextfunc)next_LuaCoroutine, + .tp_finalize = (destructor)gc_LuaFunc, }; // TODO: implement convertion to dict, list and iteration for Lua Tables and Instances @@ -120,11 +120,11 @@ PyTypeObject pLuaTable_Type = { .tp_itemsize = 0, .tp_flags = Py_TPFLAGS_DEFAULT, .tp_new = PyType_GenericNew, - .tp_init = &init_LuaTable_Wrapper, + .tp_init = (initproc)init_LuaTable_Wrapper, .tp_as_mapping = &pLuaTable_MappingMethods, - .tp_call = &call_LuaTable_Wrapper, - .tp_iter = &iter_LuaTable, - .tp_finalize = &gc_LuaTable, + .tp_call = (ternaryfunc)call_LuaTable_Wrapper, + .tp_iter = (getiterfunc)iter_LuaTable, + .tp_finalize = (destructor)gc_LuaTable, }; PyTypeObject pLuaInstance_Type = { @@ -135,16 +135,16 @@ PyTypeObject pLuaInstance_Type = { .tp_itemsize = 0, .tp_flags = Py_TPFLAGS_DEFAULT, .tp_new = PyType_GenericNew, - .tp_init = &init_LuaTable_Wrapper, + .tp_init = (initproc)init_LuaTable_Wrapper, .tp_as_number = &pLuaInstance_NumberMethods, .tp_as_mapping = &pLuaInstance_MappingMethods, - .tp_richcompare = &compare_LuaInstance_Wrapper, - .tp_getattr = &getattr_LuaInstance_Wrapper, - .tp_setattr = &setattr_LuaInstance_Wrapper, - .tp_call = &call_LuaInstance_Wrapper, - .tp_iter = &iter_LuaTable, - .tp_str = &string_LuaInstance_Wrapper, - .tp_finalize = &gc_LuaTable, + .tp_richcompare = (richcmpfunc)compare_LuaInstance_Wrapper, + .tp_getattr = (getattrfunc)getattr_LuaInstance_Wrapper, + .tp_setattr = (setattrfunc)setattr_LuaInstance_Wrapper, + .tp_call = (ternaryfunc)call_LuaInstance_Wrapper, + .tp_iter = (getiterfunc)iter_LuaTable, + .tp_str = (reprfunc)string_LuaInstance_Wrapper, + .tp_finalize = (destructor)gc_LuaTable, }; static PyTypeObject pLuaModule_Type = { @@ -155,40 +155,40 @@ static PyTypeObject pLuaModule_Type = { .tp_itemsize = 0, .tp_flags = Py_TPFLAGS_DEFAULT, .tp_new = PyType_GenericNew, - .tp_init = &PyLua_LuaInit, - .tp_getattr = &PyLua_LuaGet, - .tp_setattr = &PyLua_LuaSet, - .tp_finalize = &PyLua_LuaGC, + .tp_init = (initproc)PyLua_LuaInit, + .tp_getattr = (getattrfunc)PyLua_LuaGet, + .tp_setattr = (setattrfunc)PyLua_LuaSet, + .tp_finalize = (destructor)PyLua_LuaGC, }; static PyMappingMethods pLuaTable_MappingMethods = { - .mp_length = &len_LuaInstance_Wrapper, - .mp_subscript = &getelem_LuaTable_Wrapper, - .mp_ass_subscript = &setelem_LuaTable_Wrapper, + .mp_length = (lenfunc)len_LuaInstance_Wrapper, + .mp_subscript = (binaryfunc)getelem_LuaTable_Wrapper, + .mp_ass_subscript = (objobjargproc)setelem_LuaTable_Wrapper, }; static PyMappingMethods pLuaInstance_MappingMethods = { - .mp_length = &len_LuaInstance_Wrapper, + .mp_length = (lenfunc)len_LuaInstance_Wrapper, }; static PyNumberMethods pLuaInstance_NumberMethods = { - .nb_add = &add_LuaInstance_Wrapper, - .nb_subtract = &sub_LuaInstance_Wrapper, - .nb_multiply = &mul_LuaInstance_Wrapper, - .nb_true_divide = &div_LuaInstance_Wrapper, - .nb_floor_divide = &floordiv_LuaInstance_Wrapper, - .nb_power = &pow_LuaInstance_Wrapper, - .nb_remainder = &mod_LuaInstance_Wrapper, - .nb_negative = &neg_LuaInstance_Wrapper, - .nb_lshift = &lshift_LuaInstance_Wrapper, - .nb_rshift = &rshift_LuaInstance_Wrapper, - .nb_and = &band_LuaInstance_Wrapper, - .nb_or = &bor_LuaInstance_Wrapper, - .nb_xor = &bxor_LuaInstance_Wrapper, - .nb_invert = &bnot_LuaInstance_Wrapper, - .nb_matrix_multiply = &concat_LuaInstance_Wrapper, + .nb_add = (binaryfunc)add_LuaInstance_Wrapper, + .nb_subtract = (binaryfunc)sub_LuaInstance_Wrapper, + .nb_multiply = (binaryfunc)mul_LuaInstance_Wrapper, + .nb_true_divide = (binaryfunc)div_LuaInstance_Wrapper, + .nb_floor_divide = (binaryfunc)floordiv_LuaInstance_Wrapper, + .nb_power = (ternaryfunc)pow_LuaInstance_Wrapper, + .nb_remainder = (binaryfunc)mod_LuaInstance_Wrapper, + .nb_negative = (unaryfunc)neg_LuaInstance_Wrapper, + .nb_lshift = (binaryfunc)lshift_LuaInstance_Wrapper, + .nb_rshift = (binaryfunc)rshift_LuaInstance_Wrapper, + .nb_and = (binaryfunc)band_LuaInstance_Wrapper, + .nb_or = (binaryfunc)bor_LuaInstance_Wrapper, + .nb_xor = (binaryfunc)bxor_LuaInstance_Wrapper, + .nb_invert = (unaryfunc)bnot_LuaInstance_Wrapper, + .nb_matrix_multiply = (binaryfunc)concat_LuaInstance_Wrapper, }; @@ -204,7 +204,7 @@ static struct PyModuleDef LUA_module = { "pylua", "pylua doc", -1, - &PyLua_Methods + PyLua_Methods }; @@ -285,7 +285,7 @@ static int PyLua_LuaSet(PyLua_LuaModule* self, char* attr, PyObject* pValue) static void PyLua_LuaGC(PyLua_LuaModule* self) { // TODO: implement - return 0; + return; } @@ -385,7 +385,7 @@ static PyObject* iter_LuaCoroutine(PyLua_LuaFunc* self) } Py_INCREF(self); - return self; + return (PyObject*)self; } static PyObject* next_LuaCoroutine(PyLua_LuaFunc* self)