feat: Added proper launch under venv
This commit is contained in:
@@ -15,7 +15,9 @@
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
PYBIND11_EMBEDDED_MODULE(sqg2o, m) {
|
||||
void registerSquirrelObjects()
|
||||
{
|
||||
py::module_ m = py::module_::import("sqg2o");
|
||||
|
||||
py::class_<PyPacket>(m, "Packet")
|
||||
.def(py::init<>())
|
||||
|
||||
6
source/bind.h
Normal file
6
source/bind.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef _BINDH_
|
||||
#define _BINDH_
|
||||
|
||||
void registerSquirrelObjects();
|
||||
|
||||
#endif
|
||||
@@ -4,154 +4,9 @@
|
||||
#include "sqconstants.h"
|
||||
|
||||
namespace py = pybind11;
|
||||
extern py::module_ g2o;
|
||||
|
||||
#define GET_CONST(constName, constType) Sqrat::ConstTable().GetSlot(constName).Cast<constType>()
|
||||
|
||||
// Sadly, I have to split definition and declaration of constants, because pybind doesn't allow embeding modules inside functions
|
||||
// And in the global scope, Squirrel VM and const table is not yet exist
|
||||
|
||||
PYBIND11_EMBEDDED_MODULE(sqg2oconst, m) {
|
||||
m.attr("DAMAGE_CTX") = 0;
|
||||
m.attr("EQUIPMENT_CTX") = 0;
|
||||
|
||||
m.attr("DAMAGE_UNKNOW") = 0;
|
||||
m.attr("DAMAGE_BARRIER") = 0;
|
||||
m.attr("DAMAGE_BLUNT") = 0;
|
||||
m.attr("DAMAGE_EDGE") = 0;
|
||||
m.attr("DAMAGE_FIRE") = 0;
|
||||
m.attr("DAMAGE_FLY") = 0;
|
||||
m.attr("DAMAGE_MAGIC") = 0;
|
||||
m.attr("DAMAGE_POINT") = 0;
|
||||
m.attr("DAMAGE_FALL") = 0;
|
||||
|
||||
m.attr("DEBUG_MODE") = false;
|
||||
m.attr("SERVER_SIDE") = false;
|
||||
m.attr("CLIENT_SIDE") = false;
|
||||
|
||||
m.attr("HAND_LEFT") = 0;
|
||||
m.attr("HAND_RIGHT") = 0;
|
||||
|
||||
m.attr("ITEM_CAT_NONE") = 0;
|
||||
m.attr("ITEM_CAT_NF") = 0;
|
||||
m.attr("ITEM_CAT_FF") = 0;
|
||||
m.attr("ITEM_CAT_MUN") = 0;
|
||||
m.attr("ITEM_CAT_ARMOR") = 0;
|
||||
m.attr("ITEM_CAT_FOOD") = 0;
|
||||
m.attr("ITEM_CAT_DOCS") = 0;
|
||||
m.attr("ITEM_CAT_POTION") = 0;
|
||||
m.attr("ITEM_CAT_LIGHT") = 0;
|
||||
m.attr("ITEM_CAT_RUNE") = 0;
|
||||
m.attr("ITEM_CAT_MAGIC") = 0;
|
||||
|
||||
m.attr("ITEM_FLAG_DAG") = 0;
|
||||
m.attr("ITEM_FLAG_SWD") = 0;
|
||||
m.attr("ITEM_FLAG_AXE") = 0;
|
||||
m.attr("ITEM_FLAG_2HD_SWD") = 0;
|
||||
m.attr("ITEM_FLAG_2HD_AXE") = 0;
|
||||
m.attr("ITEM_FLAG_SHIELD") = 0;
|
||||
m.attr("ITEM_FLAG_BOW") = 0;
|
||||
m.attr("ITEM_FLAG_CROSSBOW") = 0;
|
||||
m.attr("ITEM_FLAG_RING") = 0;
|
||||
m.attr("ITEM_FLAG_AMULET") = 0;
|
||||
m.attr("ITEM_FLAG_BELT") = 0;
|
||||
m.attr("ITEM_FLAG_DROPPED") = 0;
|
||||
m.attr("ITEM_FLAG_MI") = 0;
|
||||
m.attr("ITEM_FLAG_MULTI") = 0;
|
||||
m.attr("ITEM_FLAG_NFOCUS") = 0;
|
||||
m.attr("ITEM_FLAG_CREATEAMMO") = 0;
|
||||
m.attr("ITEM_FLAG_NSPLIT") = 0;
|
||||
m.attr("ITEM_FLAG_DRINK") = 0;
|
||||
m.attr("ITEM_FLAG_TORCH") = 0;
|
||||
m.attr("ITEM_FLAG_THROW") = 0;
|
||||
m.attr("ITEM_FLAG_ACTIVE") = 0;
|
||||
|
||||
m.attr("ITEM_WEAR_NO") = 0;
|
||||
m.attr("ITEM_WEAR_TORSO") = 0;
|
||||
m.attr("ITEM_WEAR_HEAD") = 0;
|
||||
m.attr("ITEM_WEAR_LIGHT") = 0;
|
||||
|
||||
m.attr("ATTACK_RUN") = 0;
|
||||
m.attr("ATTACK_FORWARD") = 0;
|
||||
m.attr("ATTACK_LEFT") = 0;
|
||||
m.attr("ATTACK_RIGHT") = 0;
|
||||
m.attr("ACTION_CLEAR_QUEUE") = 0;
|
||||
m.attr("ACTION_APPLY_OVERLAY") = 0;
|
||||
m.attr("ACTION_REMOVE_OVERLAY") = 0;
|
||||
m.attr("ACTION_PLAY_ANI") = 0;
|
||||
m.attr("ACTION_STOP_ANI") = 0;
|
||||
m.attr("ACTION_EQUIP_ITEM") = 0;
|
||||
m.attr("ACTION_UNEQUIP_ITEM") = 0;
|
||||
m.attr("ACTION_WEAPON_MODE") = 0;
|
||||
m.attr("ACTION_DRAW_WEAPON") = 0;
|
||||
m.attr("ACTION_REMOVE_WEAPON") = 0;
|
||||
m.attr("ACTION_USE_ITEM") = 0;
|
||||
m.attr("ACTION_USE_ITEM_TO_STATE") = 0;
|
||||
m.attr("ACTION_READY_SPELL") = 0;
|
||||
m.attr("ACTION_UNREADY_SPELL") = 0;
|
||||
m.attr("ACTION_ATTACK_MELEE_WEAPON") = 0;
|
||||
m.attr("ACTION_ATTACK_RANGED_WEAPON") = 0;
|
||||
m.attr("ACTION_SPELL_CAST") = 0;
|
||||
m.attr("ACTION_USE_MOB_SCHEME") = 0;
|
||||
m.attr("ACTION_SHOOT_AT") = 0;
|
||||
m.attr("ACTION_START_AIM_AT") = 0;
|
||||
m.attr("ACTION_STOP_AIM_AT") = 0;
|
||||
m.attr("ACTION_SCRIPT") = 0;
|
||||
|
||||
m.attr("UNRELIABLE") = 0;
|
||||
m.attr("UNRELIABLE_SEQUENCED") = 0;
|
||||
m.attr("RELIABLE") = 0;
|
||||
m.attr("RELIABLE_ORDERED") = 0;
|
||||
m.attr("RELIABLE_SEQUENCED") = 0;
|
||||
|
||||
m.attr("WEAPON_1H") = 0;
|
||||
m.attr("WEAPON_2H") = 0;
|
||||
m.attr("WEAPON_BOW") = 0;
|
||||
m.attr("WEAPON_CBOW") = 0;
|
||||
|
||||
m.attr("TALENT_1H") = 0;
|
||||
m.attr("TALENT_2H") = 0;
|
||||
m.attr("TALENT_BOW") = 0;
|
||||
m.attr("TALENT_CROSSBOW") = 0;
|
||||
m.attr("TALENT_PICK_LOCKS") = 0;
|
||||
m.attr("TALENT_PICKPOCKET") = 0;
|
||||
m.attr("TALENT_MAGE") = 0;
|
||||
m.attr("TALENT_SNEAK") = 0;
|
||||
m.attr("TALENT_REGENERATE") = 0;
|
||||
m.attr("TALENT_FIREMASTER") = 0;
|
||||
m.attr("TALENT_ACROBATIC") = 0;
|
||||
m.attr("TALENT_PICKPOCKET_UNUSED") = 0;
|
||||
m.attr("TALENT_SMITH") = 0;
|
||||
m.attr("TALENT_RUNES") = 0;
|
||||
m.attr("TALENT_ALCHEMY") = 0;
|
||||
m.attr("TALENT_THROPHY") = 0;
|
||||
m.attr("TALENT_A") = 0;
|
||||
m.attr("TALENT_B") = 0;
|
||||
m.attr("TALENT_C") = 0;
|
||||
m.attr("TALENT_D") = 0;
|
||||
m.attr("TALENT_E") = 0;
|
||||
m.attr("TALENT_MAX") = 0;
|
||||
|
||||
m.attr("WEAPONMODE_NONE") = 0;
|
||||
m.attr("WEAPONMODE_FIST") = 0;
|
||||
m.attr("WEAPONMODE_DAG") = 0;
|
||||
m.attr("WEAPONMODE_1HS") = 0;
|
||||
m.attr("WEAPONMODE_2HS") = 0;
|
||||
m.attr("WEAPONMODE_BOW") = 0;
|
||||
m.attr("WEAPONMODE_CBOW") = 0;
|
||||
m.attr("WEAPONMODE_MAG") = 0;
|
||||
m.attr("WEAPONMODE_MAX") = 0;
|
||||
|
||||
m.attr("WEATHER_SNOW") = 0;
|
||||
m.attr("WEATHER_RAIN") = 0;
|
||||
|
||||
m.attr("AC_SPEED_HACK") = 0;
|
||||
|
||||
m.attr("DISCONNECTED") = 0;
|
||||
m.attr("LOST_CONNECTION") = 0;
|
||||
m.attr("HAS_CRASHED") = 0;
|
||||
}
|
||||
|
||||
void registerSquirrelConstants()
|
||||
{
|
||||
py::module_ cts = py::module_::import("sqg2oconst");
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "sqevents.h"
|
||||
#include "sqconstants.h"
|
||||
#include "squirrel/functions.h"
|
||||
#include "bind.h"
|
||||
|
||||
namespace py = pybind11;
|
||||
py::scoped_interpreter guard{};
|
||||
@@ -16,16 +17,20 @@ extern "C" SQRESULT SQRAT_API sqmodule_load(HSQUIRRELVM vm, HSQAPI api)
|
||||
|
||||
try
|
||||
{
|
||||
registerSquirrelConstants();
|
||||
|
||||
py::dict locals = py::dict();
|
||||
py::exec(R"(
|
||||
import site
|
||||
import json
|
||||
import sys
|
||||
import importlib
|
||||
|
||||
venv_path = 'test_venv/Lib/site-packages'
|
||||
import importlib.util
|
||||
site.addsitedir('.')
|
||||
|
||||
|
||||
spec = importlib.util.find_spec("g2o")
|
||||
if spec is not None:
|
||||
if spec.submodule_search_locations:
|
||||
sys.path.append(spec.submodule_search_locations[0])
|
||||
|
||||
entry_point = 'pyg2o_entry'
|
||||
|
||||
try:
|
||||
@@ -36,12 +41,20 @@ extern "C" SQRESULT SQRAT_API sqmodule_load(HSQUIRRELVM vm, HSQAPI api)
|
||||
pass
|
||||
|
||||
try:
|
||||
importlib.import_module(entry_point)
|
||||
spec = importlib.util.find_spec(entry_point)
|
||||
if spec is not None:
|
||||
if spec.submodule_search_locations:
|
||||
sys.path.append(spec.submodule_search_locations[0])
|
||||
except Exception as e:
|
||||
print(e)
|
||||
)");
|
||||
)", py::globals(), locals);
|
||||
|
||||
registerSquirrelConstants();
|
||||
registerSquirrelObjects();
|
||||
g2o = py::module_::import("g2o");
|
||||
|
||||
py::module_ importlib = py::module_::import("importlib");
|
||||
importlib.attr("import_module")(locals["entry_point"]);
|
||||
}
|
||||
catch (py::error_already_set &e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user