🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Adding functions to externally defined type

Started by
3 comments, last by Suudy 18 years, 8 months ago
Suppose I define an object type with:

engine->RegisterObjectType("CTest", 0, asOBJ_CLASS);
And I register a few functions with:

engine->RegisterObjectMethod("CTest", "void foo()", asMETHOD(CTest, foo), asCALL_THISCALL);
Where CTest is a defined class with member function foo. Finally, I define a global property with:

engine->RegisterGlobalProperty("CTest test", &test_obj);
Where test_obj is an instance of CTest. From a script, can I add methods to the externally registered type? (I don't know that object methods are permitted for things like structs.) For example, in AngelScript:

void CTest.bar()
{
  // Do something
}
Advertisement
AngelScript cannot modify any types after they have been declared.

I haven't decided what kind of object model AngelScript will use in a future version. Should I go with metaclasses, then something like this would be possible. However, I doubt that this will be the solution.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Darn! ;)

The problem I'm trying to solve involves using the asIScriptContext::Suspend() and asIScriptContext::Execute() to do external operations in our single-threaded environment.

Unfortunately, when I call asIScriptContext::Execute() I need it to return before the rest of our system can continue processing. And using asIScriptContext::Suspend(), I can make this happen. However, we have an existing code base that uses something like:
uint x;x = tcon.read(0x1234, 0x4567);

In the older system, tcon was registered as a global property of type CTcon. And tcon.read() was a registered method. Our older system could perform all the operations in the external method. So asIScriptContext::Execute() would never need to return.

However, the new system cannot do those operations within the externally registered methods. They have to happen independently of asIScriptContext::Execute(). My idea was to have asIScriptContext::Execute() return. When it returns, the caller examines some data store to determine why asIScriptContext::Execute() returned and then do whatever tasks are necessary. So when tcon.read() is called, it saves off the necessary information then calls asIScriptContext::Suspend().

The problem is that calling asIScriptContext::Suspend() will (I think) complete the current AngelScript line and suspend after that line. So now I have to split the operation into two operations, i.e.:
uint x;tcon.start_read(0x1234, 0x4567); // asIScriptContext::Suspend() called herex = tcon.end_read();

Which is fine--except for the existing code base that is used to tcon.read() in a single operation. So I thought perhaps I could add something with asIScriptEngine::AddScriptSection() that would define tcon.read() to look like:
uint tcon.read(uint req, uint addr){  tcon.start_read(req, addr);  return tcon.end_read();}

Which keeps the old code compatible.

Does what I'm doing make sense? Any other suggestions? Or am I stuck changing the old code?
I cannot see any way to easily allow the read() method suspend the script execution so that the return value is only passed to the script once execution starts again. That would require the script engine to restart from inside the read() method on the part where it returns the value.

Isn't there some way you can alter the implementation of registered read() method so that it doesn't have to stop the execution of the script? Why does the script have to be halted for the method to work?

Unless you can make the read() method compatible with the old code you'll have to change your old scripts. Maybe you can write a script function so that the code can be converted with a simple search-and-replace.


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Quote: Original post by WitchLord
Isn't there some way you can alter the implementation of registered read() method so that it doesn't have to stop the execution of the script? Why does the script have to be halted for the method to work?

Unfortunately, no. I am using the VHPI (the VHDL procedural language interface) and it requires all VHPI calls to return before the simulation continues. And since the read function depends upon the simulation running...

Quote: Original post by WitchLord
Unless you can make the read() method compatible with the old code you'll have to change your old scripts. Maybe you can write a script function so that the code can be converted with a simple search-and-replace.

Or use the pre-processor....

This topic is closed to new replies.

Advertisement