Advertisement

Setting an exception instead of returning with the generic calling convention?

Started by April 20, 2024 03:34 PM
2 comments, last by natinusala 7 months, 1 week ago

Hello,

The documentation states that the application can throw C++ exceptions and the AS VM will automatically catch them, fail the current script context and return back to the application.

However, this assumes that the application is a C++ application - I am currently working on Swift bindings for AngelScript, and Swift cannot throw nor catch C++ exceptions. My current implementation uses the AS C interface with cdecl and cdeclObjfirst calling conventions, which cannot throw exceptions either.

I need to be able to throw exceptions from the application to AS for null-safety reasons: right now if Swift receives a null handle as a function parameter, I have no choice but to crash the whole program. That is because with the C calling convention, I have no way to fail the current script context execution without returning anything (it's a Swift safety constraint and a calling convention limitation).

So I wondered, if I were to use the generic calling convention instead of cdecl, would I be able to “throw” an exception instead of returning a value? I don't see any method to set exceptions on asIScriptGeneric so I assume not, but I figured I could ask here.

Thanks!

None

You would set the exception on the context that is calling the function.

asIScriptContext *ctx = asGetActiveContext();

ctx->SetException("null pointer");

Regards,

Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement

Okay, I will try this out. Thanks!

None

This topic is closed to new replies.

Advertisement