Skip to content

Commit

Permalink
Fix multiple commands/modules in scripting
Browse files Browse the repository at this point in the history
  • Loading branch information
Imrglop committed Oct 1, 2024
1 parent 920f20e commit f550f62
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/client/script/JsScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,16 @@ class JsScript {
JsErrorCode compileScript();

struct Resource {
void* ptr;
std::shared_ptr<void> ptr;
std::function<void(void* object)> finalize;

Resource(void* ptr, decltype(finalize) finalizer) : ptr(ptr), finalize(finalizer) {}

~Resource() {
finalize(ptr);
}
Resource(void* ptr, decltype(finalize) finalizer) : ptr(ptr, finalizer), finalize(finalizer) {}
};

void addResource(void* object, decltype(Resource::finalize) finalizer) { this->resources.emplace_back(object, finalizer); };
void removeResource(void* object) {
for (auto it = resources.begin(); it != resources.end(); ++it) {
if (it->ptr == object) resources.erase(it);
if (it->ptr.get() == object) resources.erase(it);
}
}
protected:
Expand Down

0 comments on commit f550f62

Please sign in to comment.