🎉 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!
Scripting System Basics
Check out:
http://habitat3d.sourceforge.net
It does pretty much the same thing you are trying to do.
http://habitat3d.sourceforge.net
It does pretty much the same thing you are trying to do.
quote: Original post by Biggles
for example, a C function used by the script to draw a rectangle on the screen would need to be able to access the display object, eg Display::DrawRect), which have been encapsulated inside the main engine class. How do I get around this problem without breaking encapsulation? Is it even possible?
Well, duh, you have to decide on whether you want the script system to be able to acces those classes and manipulate the entities they represent, or if they should be locked away.
Breaking encapsulation means you provide an access that can let a third party programmer leave your objects in invalid states (violate their invariant), for example, by changing values of internal pointers, without code that manages those pointers being notified (like the ''next'' pointers in a linked list). What you are doing is to add new functions that can manipulate the object, but which are still expected to leave the objects in a valid state (assuming they were in a valid state to start with, which is what encapsulation is intended to ensure). So your are just exposing a new (scripting) interface.
Implementation note: extern "C" static member functions can be useful when you need to write functions callable from C, that access private members of a class, without violating encapsulation. Obviously, being static, they need an object pointer (C doesn''t have references) among their arguments.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement