fix: Crash on adding name key into kwargs dictionary
+ Changed file structure for events
This commit is contained in:
2
.github/workflows/docs_pages.yml
vendored
2
.github/workflows/docs_pages.yml
vendored
@@ -3,7 +3,7 @@ name: docs
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- master
|
||||
|
||||
jobs:
|
||||
docs:
|
||||
|
||||
39
src/events/sqevents.cpp
Normal file
39
src/events/sqevents.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <sqapi.h>
|
||||
#include <pybind11/embed.h>
|
||||
#include "sqevents.h"
|
||||
#include "sqcontainers.h"
|
||||
|
||||
namespace py = pybind11;
|
||||
using namespace pybind11::literals;
|
||||
|
||||
extern py::module_ g2o;
|
||||
|
||||
void addEventHandler(const char* eventName, SQFUNCTION closure, unsigned int priority = 9999)
|
||||
{
|
||||
using namespace SqModule;
|
||||
|
||||
Sqrat::Function sq_addEventHandler = Sqrat::RootTable().GetFunction("addEventHandler");
|
||||
|
||||
if (sq_addEventHandler.IsNull())
|
||||
return;
|
||||
|
||||
HSQOBJECT closureHandle;
|
||||
|
||||
sq_newclosure(vm, closure, 0);
|
||||
sq_getstackobj(vm, -1, &closureHandle);
|
||||
|
||||
Sqrat::Function func(vm, Sqrat::RootTable().GetObject(), closureHandle);
|
||||
sq_addEventHandler(eventName, func, priority);
|
||||
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
|
||||
void registerSquirrelEvents()
|
||||
{
|
||||
addEventHandler("onInit", sq_onInit, 0);
|
||||
addEventHandler("onExit", sq_onExit, 0);
|
||||
addEventHandler("onTick", sq_onTick, 0);
|
||||
addEventHandler("onTime", sq_onTime, 0);
|
||||
addEventHandler("onBan", sq_onBan, 0);
|
||||
addEventHandler("onUnban", sq_onUnban, 0);
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
#pragma once
|
||||
#ifndef _SQEVENTS_H_
|
||||
#define _SQEVENTS_H
|
||||
|
||||
SQInteger sq_onInit(HSQUIRRELVM);
|
||||
SQInteger sq_onExit(HSQUIRRELVM);
|
||||
SQInteger sq_onTick(HSQUIRRELVM);
|
||||
SQInteger sq_onTime(HSQUIRRELVM);
|
||||
SQInteger sq_onBan(HSQUIRRELVM);
|
||||
SQInteger sq_onUnban(HSQUIRRELVM);
|
||||
|
||||
void registerSquirrelEvents();
|
||||
|
||||
#endif
|
||||
@@ -1,32 +1,13 @@
|
||||
#include <sqapi.h>
|
||||
#include <pybind11/embed.h>
|
||||
#include "sqcontainers.h"
|
||||
#include "sqevents.h"
|
||||
|
||||
namespace py = pybind11;
|
||||
using namespace pybind11::literals;
|
||||
|
||||
extern py::module_ g2o;
|
||||
|
||||
void addEventHandler(const char* eventName, SQFUNCTION closure, unsigned int priority = 9999)
|
||||
{
|
||||
using namespace SqModule;
|
||||
|
||||
Sqrat::Function sq_addEventHandler = Sqrat::RootTable().GetFunction("addEventHandler");
|
||||
|
||||
if (sq_addEventHandler.IsNull())
|
||||
return;
|
||||
|
||||
HSQOBJECT closureHandle;
|
||||
|
||||
sq_newclosure(vm, closure, 0);
|
||||
sq_getstackobj(vm, -1, &closureHandle);
|
||||
|
||||
Sqrat::Function func(vm, Sqrat::RootTable().GetObject(), closureHandle);
|
||||
sq_addEventHandler(eventName, func, priority);
|
||||
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
|
||||
SQInteger sq_onInit(HSQUIRRELVM vm)
|
||||
{
|
||||
py::object result = g2o.attr("callEvent")("onInit");
|
||||
@@ -82,13 +63,3 @@ SQInteger sq_onUnban(HSQUIRRELVM vm)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void registerSquirrelEvents()
|
||||
{
|
||||
addEventHandler("onInit", sq_onInit, 0);
|
||||
addEventHandler("onExit", sq_onExit, 0);
|
||||
addEventHandler("onTick", sq_onTick, 0);
|
||||
addEventHandler("onTime", sq_onTime, 0);
|
||||
addEventHandler("onBan", sq_onBan, 0);
|
||||
addEventHandler("onUnban", sq_onUnban, 0);
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <pybind11/embed.h>
|
||||
#include <iostream>
|
||||
#include <pybind11/embed.h>
|
||||
#include "sqevents.h"
|
||||
#include "events/sqevents.h"
|
||||
|
||||
namespace py = pybind11;
|
||||
py::scoped_interpreter guard{};
|
||||
|
||||
@@ -19,14 +19,10 @@ py::dict sqParseTable(Sqrat::Table tab)
|
||||
if (key._type != OT_STRING)
|
||||
continue;
|
||||
|
||||
py::str pkey = "{0}_";
|
||||
|
||||
switch(value._type)
|
||||
{
|
||||
case OT_STRING:
|
||||
// TODO: for some reason, key names 'name' and 'reason' crashing the server (maybe some more)
|
||||
// Adding _ to key names is fixing this, but need to find a better solution
|
||||
result[pkey.format(sq_objtostring(&key))] = sq_objtostring(&value);
|
||||
result[sq_objtostring(&key)] = sq_objtostring(&value);
|
||||
break;
|
||||
case OT_INTEGER:
|
||||
result[sq_objtostring(&key)] = sq_objtointeger(&value);
|
||||
|
||||
Reference in New Issue
Block a user