feat: Added ability to change entry point name
+ Renamed default entry point name + Added proper exception handling + Added ability to use .pth files
This commit is contained in:
@@ -6,7 +6,6 @@ namespace py = pybind11;
|
||||
using namespace pybind11::literals;
|
||||
|
||||
extern py::module_ g2o;
|
||||
extern py::module_ pysys;
|
||||
|
||||
void addEventHandler(const char* eventName, SQFUNCTION closure, unsigned int priority = 9999)
|
||||
{
|
||||
@@ -40,7 +39,7 @@ void callEvent(const char* eventName, py::dict kwargs)
|
||||
}
|
||||
catch (py::error_already_set &e)
|
||||
{
|
||||
pysys.attr("stderr").attr("write")(e.what());
|
||||
py::print(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,15 +7,7 @@
|
||||
namespace py = pybind11;
|
||||
py::scoped_interpreter guard{};
|
||||
|
||||
py::module_ pysys = py::module_::import("sys");
|
||||
py::module_ g2o;
|
||||
py::module_ scripts;
|
||||
|
||||
int main()
|
||||
{
|
||||
system("pause");
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" SQRESULT SQRAT_API sqmodule_load(HSQUIRRELVM vm, HSQAPI api)
|
||||
{
|
||||
@@ -25,16 +17,38 @@ extern "C" SQRESULT SQRAT_API sqmodule_load(HSQUIRRELVM vm, HSQAPI api)
|
||||
try
|
||||
{
|
||||
registerSquirrelConstants();
|
||||
registerSquirrelEvents();
|
||||
|
||||
|
||||
py::exec(R"(
|
||||
import site
|
||||
import json
|
||||
import importlib
|
||||
|
||||
venv_path = 'test_venv/Lib/site-packages'
|
||||
site.addsitedir('.')
|
||||
|
||||
entry_point = 'pyg2o_entry'
|
||||
|
||||
try:
|
||||
with open('pyg2o.json', 'r') as f:
|
||||
json = json.loads(f.read())
|
||||
entry_point = json['entry']
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
try:
|
||||
importlib.import_module(entry_point)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
)");
|
||||
|
||||
g2o = py::module_::import("g2o");
|
||||
scripts = py::module_::import("scripts");
|
||||
|
||||
}
|
||||
catch (py::error_already_set &e)
|
||||
{
|
||||
pysys.attr("stderr").attr("write")(e.what());
|
||||
py::print(e.what());
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
|
||||
registerSquirrelEvents();
|
||||
return SQ_OK;
|
||||
}
|
||||
Reference in New Issue
Block a user