Make TProgramInfo.ScriptObj available to the Instance.OnInstantiate event handler
Background
In my framework many external objects (i.e. the Delphi side objects) are in fact proxy objects that contain both a reference to the Delphi side TObject
and a reference to the script side IScriptObj
.
The problem
I need to expose a static Delphi side object to the script.
The script side declaration must be available at compile time but the Delphi object instance is only available at run time. For various reasons I cannot use ExposeInstanceToUnit()
for this particular object.
The most natural choice seems to be to expose the object via the OnInstantiate
event handler of a dwsUnit Instance object.
The problem is that when OnInstantiate
is called the script side IScriptObj
hasn't been created yet so I cannot save a reference to it in my proxy object.
Compare this to the OnEval
handler of a constructor where TProgramInfo.ScriptObj
is valid when the handler is called.
The solution
I propose that TInstantiateFunc.Call()
be modified so TProgramInfo.ScriptObj
is initialized before the OnInstantiate
handler is called.
Comments (2)
-
repo owner -
reporter Even though the internal
ScriptObj
has now been instantiated it is still not exposed to theOnInstantiate
handler:TProgramInfo.ScriptObj
is still nil.I'll create a test case.
- Log in to comment
Pushed a change, is that what you are after?
If not, please add a test case in UInstantiateTests, instances is a part of DWScript I have personally never used :)