Exposing script data to C
by Nicki Vankoughnett · in Torque Game Engine · 07/25/2006 (10:31 am) · 7 replies
The means by which C++ classes are exposed to Torque Script are fairly well documented, and I have found examples which demonstrate how to call a function belonging to a datablock in C++.
What I would like to do, however, is essentially define a datablock or script object class, and to provide a pointer or other means of accessing / invoking it to C++. Ideally, this should let me manage which set of script code I am executing in C++, by deciding which datablock / script object is currently active.
So, is there any sane way to do this? I know I can pass simple data types, like ints or position info from script code to C++.
This is probably a case of me looking right at what I want to do without seeing it, or a case of me wanting to do something that TorqueScript just does not support.
END COMMUNICATION
What I would like to do, however, is essentially define a datablock or script object class, and to provide a pointer or other means of accessing / invoking it to C++. Ideally, this should let me manage which set of script code I am executing in C++, by deciding which datablock / script object is currently active.
So, is there any sane way to do this? I know I can pass simple data types, like ints or position info from script code to C++.
This is probably a case of me looking right at what I want to do without seeing it, or a case of me wanting to do something that TorqueScript just does not support.
END COMMUNICATION
About the author
#2
Of coz, that's just my reading of what he said, I could be wrong.
07/25/2006 (11:37 am)
I got the impression he was actually looking to know how to reference data, no functionality... more along the lines of accessing "$foo" or "FooSimObject".Of coz, that's just my reading of what he said, I could be wrong.
#3
Lets say I instance FooSimObject in script, as well as FooOtherObject of the same type.
I want to be able to pass both instances to an array stored in a C++ class, ideally as pointers. From within the code, I want to be able to call either FooSimObject::someFunction() or FooOtherObject::someFunction().
The idea is to be able to define the functions in script code, but to have them called from C++. Sort of like having a base class in C++ but the derived class in TorqueScript. The C++ code would determine which of the two instances is the current one, and call the script functions accordingly.
Thanks.
END COMMUNICATION
07/25/2006 (1:55 pm)
Cliff is right, I am wondering about passing data instanced in a Torque script back to the C++ side.Lets say I instance FooSimObject in script, as well as FooOtherObject of the same type.
I want to be able to pass both instances to an array stored in a C++ class, ideally as pointers. From within the code, I want to be able to call either FooSimObject::someFunction() or FooOtherObject::someFunction().
The idea is to be able to define the functions in script code, but to have them called from C++. Sort of like having a base class in C++ but the derived class in TorqueScript. The C++ code would determine which of the two instances is the current one, and call the script functions accordingly.
Thanks.
END COMMUNICATION
#4
07/25/2006 (2:29 pm)
Regarding passing it in, you can have ConsoleMethods that take the data as parameters... but this won't help you if you are wanting to do it outside the normal calls.
#5
executef() not working for you ?
BTW folks, this really belongs in the Torque SDK owner's forum, as it's about engine source.
07/25/2006 (2:34 pm)
Quote:
From within the code, I want to be able to call either FooSimObject::someFunction() or FooOtherObject::someFunction()
executef() not working for you ?
BTW folks, this really belongs in the Torque SDK owner's forum, as it's about engine source.
#6
07/25/2006 (2:49 pm)
Good catch, Orion. I missed that, but then I can't feel too bad... so did Pat. heh.
#7
END COMMUNICATION
07/26/2006 (8:06 am)
Ok, I will resume the line of inquiry in the SDK Owners forum.END COMMUNICATION
Torque 3D Owner Pat Wilson
You can execute a function on a specific object like so:
This will then execute the corosponding script code:
function SomeSimObjectClass::someFunction( %this ) { ... }Now you can specialize the code to a certain object as well, so for example:new SomeSimObject( FooSimObject ); function FooSimObject::someFunction( %this ) { ... }Now if you called the Con::executef on a generic 'SomeSimObject' it would execute the first script code block, whereas if it was called on FooSimObject, it would execute the second code block.Is this where you are going with this?