🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Communication with C++ from script side

Started by
0 comments, last by WitchLord 10 years, 5 months ago

Hello,

I'm trying to figure out the best way for flexible communication between script side and C++ side. What are you using when you need to call some specific C++ object method from AS script without registering it through script engine?

I have event system, but it rather works in other direction (C++ sending events to Angelscript) and I'd like to keep it that way (one sided).

Lets consider situation where I have LoginState C++ class that handles logging logic and owns GUI overlay thats scripted in AS. In that script, I gather inputs, validate them and should call C++ method to send username/password through network interface. I don't want to expose network interface to scripting, but I'd like to have Auth(login, password) method available on script side.

Is registering LoginState as a OBJ_REF | OBJ_NOHANDLE type with a method Auth(login, password), then setting global property "LoginState state" the only way? Its a bit problematic with how script interface has to be registered, I'd need to register all possible methods prior to launching the state.

Or I should invent some event system that works both sides? Where script can do "eventSystem.fire("auth", dict())" where dict has login/password and some method on C++ side listens for such event? I don't like event systems much, I use libRocket events for UI side, so I can launch some events from C++, but I'd rather keep it that way, because it fires events in UI widgets, and I want to keep them script-only so I don't even query them on C++ side. This means I'd need another event system for AS->C++ communication.

Maybe someone uses different methods to call some function with parameters on C++ side from AS?

PS. In case someone wants to discuss it live, I'm on #angelscript irc channel (@freenode) 24/7, my session hangs there but when I'm not afk I look there from time to time.


Where are we and when are we and who are we?
How many people in how many places at how many times?
Advertisement

Implementing an event system for something like this seems to be a bit drastic. Why don't you just write a simple global function and register it with AngelScript, perhaps something like this:

int Auth(const string &user, const string &password)
{
   LoginState *ls = GetLoginState();
   return ls->Auth(user, password);
}
 
// Register it with AngelScript using the following call
engine->RegisterGlobalFunction("int Auth(const string &in, const string &in)", asFUNCTION(Auth), asCALL_CDECL);

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

This topic is closed to new replies.

Advertisement