Advertisement Jump to content
Sign in to follow this  

Communication with C++ from script side

This topic is 1821 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts



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 ""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.

Edited by noizex

Share this post

Link to post
Share on other sites

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);

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!