Advertisement

Function pointer (in this case function ID) within angelscript

Started by April 06, 2009 01:18 AM
0 comments, last by WitchLord 15 years, 7 months ago
Is it possible to get the ID of a function within an angelscript script? I'm making an event-orientated plugin system that uses angelscript and plugin might look like this:
const int MAX_PLAYERS = 32;

//This will be called when a new player has joined
bool EventNewPlayer()
{
  return true;
}

void main()
{
  AddEvent(EVENT_NEW_PLAYER, EventNewPlayer);
}

I was hoping that putting the function name in AddEvent would return its function ID. Any way i can get its function ID?
I haven't implemented support for function pointers yet. However you can get the id of the function by implementing a function that determines the id from the name, e.g:

void GetFunctionId(std::string &name){  // Get the context and engine  asIScriptContext *ctx = asGetActiveContext();  asIScriptEngine *engine = ctx->GetEngine();  // Get the module from the current function  int currFunc = ctx->GetCurrentFunction();  asIScriptFunction *func = engine->GetFunctionDescriptorById(currFunc);  asIScriptModule *module = engine->GetModule(func->GetModuleName());  // Get the function id from the module  return module->GetFunctionIdByName(name.c_str());}

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