Scripting System Basics

Started by
12 comments, last by Biggles 20 years, 3 months ago
Looks like all you need is Python...
So... Muira Yoshimoto sliced off his head, walked 8 miles, and defeated a Mongolian horde... by beating them with his head?

Documentation? "We are writing games, we don't have to document anything".
Advertisement
Check out:

http://habitat3d.sourceforge.net

It does pretty much the same thing you are trying to do.
---------------------http://www.stodge.net
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.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
OK, I think I understand how it all fits together now. Thanks for the help, everyone

--------------------
Never eat anything bigger than your own head.
--------------------Never eat anything bigger than your own head.

This topic is closed to new replies.

Advertisement