question about registering functions as callbacks for custom class?
Los mantenedores suelen responder en 3 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Error
- Claridad
- Necesita aclaración
- Estado de actividad
- Estancado
- Stack tecnológico
- c, cpp, javascript
- Área
- tooling
Línea de trabajo
Start from the myClass_addEventListener example in the issue and trace the JS_Call path, including how the stored callback is retained and invoked from main.cpp. Reproduce the callback and post-call failure, then document a working event-trigger path with correct callback lifetime handling.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
i'm currently trying to embed quickjs into my own project where i have my own custom classes, i'm a little confused on how to set up a callback and cant for the life of me find any answers online. my current js script looks like this:
import { MyClass } from "MyClass"
let c = new MyClass();
c.addEventListener("callback", arbitraryFunctionName);
function otherFunction()
{
print("update()");
}
function arbitraryFunctionName()
{
print("function successfully called from main.cpp");
otherFunction(); // when testing this didn't work because of scope?
}
i'm registering my callback functions into a std::map like so:
static JSValue myClass_addEventListener(
JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
std::cout << "CXX: myClass_addEventListener" << std::endl;
auto* object = static_cast<MyClassData *>(JS_GetOpaque2(ctx, this_val, MyClassID));
// Check if correct arguments are provided
if (!object || argc != 2 || !JS_IsString(argv[0]) || !JS_IsFunction(ctx, argv[1]))
return JS_ThrowTypeError(ctx, "Expected a string and a function as arguments");
// Convert the event type argument to a string
const char* eventType = JS_ToCString(ctx, argv[0]);
// Store the callback function in the object
JSValue function = JS_DupValue(ctx, argv[1]);
object->eventListeners[eventType] = function;
// This does call the function but seg faults straight after, and not practical
// would be good to call some sort of triggerEvent() function from main.cpp?
// JSValue result = JS_Call(ctx, function, this_val, 0, nullptr);
// JS_FreeValue(ctx, function);
// JS_FreeValue(ctx, result);
JS_FreeCString(ctx, eventType);
return JS_UNDEFINED;
}
- Lenguaje dominante
- C
- Estrellas
- 11.1k
- Forks
- 1.2k
- Merge medio
- 11 h 20 min
- PR fusionados (30 d)
- 1
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de bellard/quickjs
-
Collecting WeakMap keys requires multiple GC passesPosiblemente ocupada @jluxenberg la tomó hace 3 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
bellard/quickjs#581 · 2 comentarios ·
Los mantenedores suelen responder en 3 días
-
Dificultad 4/5 1-2 días Aptitud para principiantes 48/100
Los mantenedores suelen responder en 3 días
-
Failed Build/Compile On CygwinAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 58/100
bellard/quickjs#575 · 1 comentario ·
Los mantenedores suelen responder en 3 días
-
Dificultad 3/5 1-2 días Aptitud para principiantes 76/100
Los mantenedores suelen responder en 3 días
-
Update to Unicode 18.0.0Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 50/100
bellard/quickjs#559 · 2 comentarios ·
Los mantenedores suelen responder en 3 días
Todos los issues de bellard/quickjs
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 80/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
eunomia-bpf/bpfix#7 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
python-pillow/Pillow#10370 · 1 comentario ·
Los mantenedores suelen responder en 1 día