Skip to main content
gamedev.net
🔒 Locked

Embedded scripting and C++ coding questions

Started by Scourage Nov 6, 2002 at 9:31 AM 0 replies 600+ views
Original Post
Scourage
Scourage
I''m trying to build a game that has many game entites(each an C++ object) I would like each entity to have it''s own script to run for AI, since they will each differ slightly. As each script runs, I would like it to be able to call some of it''s own member functions to update position, target, etc... Many of the objects are derived from the same base object. I''m currently looking at embedding Tcl as the game script interpreter, but I''m open to changing to Lua, Python, Ruby, or any other scripting language that would work. Question 1: I''m not too clear on how a C++ object keeps it''s compiled function code in memory. Does each object of a class type have it''s own machine code in memory for each of it''s member functions, or does the compiler only create one set of machine code for the member functions of a class type and runs it for each object on that particular objects data?. Question 2: Depending on the answers from question 1, Would it be smarter to register the base class functions once with the interpreter, or do I need to have each object register it''s member functions with the script interpreter when the object is created (using different namespaces to differ between like named functions) and remove them when the object''s destructor is called. Thanks for any help

[size="3"]Halfway down the trail to Hell...
krez
krez
1) there is only one copy of the functional code in your compiled program, and the computer uses the same code for each object of the same type. a pointer to the object is automatically passed to the member functions when they are called (you don''t see thing in your c++ code, but the compiler puts it in there).
ever use the this pointer in a class?

2) it would probably be best to register the functions once for the base class, if you are using "proper" OOP everything you need should be available through that anyway. just remember to pass a pointer (or reference) to the object in question when your scripting engine runs the code...
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.