RTTI Integration #3
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
BeRo1985/poca#3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Is there an example of pascal app integration - exposing pascal classes via RTTI or registering global methods like in besen?
Seems like the only example how to expose a class inside poca is in POCARunCore.pas:
class is extended from TPOCANativeObject type TRandomNumberGenerator=class(TPOCANativeObject) (similar to how besen is from TBESENNativeObject)
instead of RegisterNativeObject there is:
POCAHashSet(Context,Instance.Globals.Namespace,POCANewUniqueString(Context,'RandomNumberGenerator'),POCANewNativeObject(Context,TRandomNumberGenerator.Create(Instance,Context,nil,nil,false)));and the magic create method equivalent to besen's ConstructObject is create_:
function TRandomNumberGenerator.create_(const Context:PPOCAContext;const This:TPOCAValue;const Arguments:PPOCAValues;const CountArguments:longint):TPOCAValue;As a small side note: I have extended the TPOCANativeObject class so that it can now also include "foreign" classes with its RTTI functionality. This should make it easier to expose existing Pascal classes without having to derive them from TPOCANativeObject directly. :-)
Ok, but what part does this support? properties, methods?
Still.. a good example for usage for this would be very helpful.
For both properties and methods, you can use this pattern. Here's an example:
where you can use
AddObjectof TPOCANativeObject to include this "foreign" class in your POCA module, without being derived from TPOCANativeObject itself. In this way, you can encapsulate useful functionality in separate classes and expose them to POCA scripts, without needing to inherit from TPOCANativeObject directly.Speaking of usage, you can do something like this:
but attention: the ownership of
MyUseFulClassInstanceis not transferred toExampleNativeObject, so you need to manage its lifetime separately, as shown in the example above. So it isn't freed whenExampleNativeObjectis freed, and also not garbage collected by POCA. This is important to avoid memory leaks or dangling pointers. But in this way, you can have "foreign" classes integrated into POCA modules easily.Is there a chance that RTTI is also used for invoke calls - so that it is not array of PPOCAValues?
This is a major issue with besen as well. i wrote a code generator ( https://github.com/JernejL/besen_interface_generator ) to generate these in order to easily interface from script to native code & back.