From GridLAB-D Wiki
Publishing methods - Procedure to publish methods
Synopsis
FUNCTIONADDR (*call)(OBJECT *object); gl_publish_function(CLASS *oclass, const char *name, FUNCTIONADDR call); FUNCTIONADDR gl_get_function(OBJECT *obj, const char *name);
Remarks
Classes may expose methods to other classes using the gl_publish_function API call. The function address can then be looked up and called as needed. The argument list is not specified and thus cannot be verified when the method is called.
Example
- Target class
#include <stdarg.h> #include "gridlabd.h" EXPORT void* my_function(OBJECT *obj, ...) { va_list ptr; va_start(ptr,obj); // TODO implement your function here va_end(ptr); return NULL; // TODO return data pointer }
- Calling class
#include "gridlabd.h" gld_object *target = get_object("target_object_name"); FUNCTIONADDR my_function = target->get_function("my_function"); void *result = my_function(target->my()); // TODO add arguments to call
Issues
- As of Hassayampa (Version 3.0)
- Methods cannot be called from other instances of GridLAB-D.
See also
- Guide to Programming GridLAB-D
- Introduction
- Creating a module
- Creating a class
- Special Topics
- Source documentation
- Validation
- Debugging
- Code templates