Archived

This topic is now archived and is closed to further replies.

Derived Classes and Compilation (Own Scripting Language)

This topic is 6599 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sorry, I can't answer your question, but I'm planning on writing a scriptlanguage of my,
and I wonder if you know any good books or webpages with some nice info?

Share this post


Link to post
Share on other sites
My suggestion:

do it like they do in c++
make the functions that you want to override in derrived classes virtual and store the pointer to them in a vtable. If a child class then overrides such a virtual function, it just writes the pointer to the new function into the vtable.
anyway, I'm not very experienced yet with scripting languages and stuff, so there might be better solutions.

code:

parent class
{
//virtual function virtFn(params)
vtable [
ptr to virtFn(params)
//contains pointer to virtFn
]
}

child class
{
//virtual function virtFn(params) //overriden fn
vtable [
ptr to virtFn(params)
//contains pointer to child virtFn instead of parent class virtFn
]
}


HTH

[This message has been edited by Chappa (edited November 22, 1999).]

Share this post


Link to post
Share on other sites
Hi all !!

The last days I created my own scripting language from scratch (I did not use Lex or Yacc, I created the parser from scratch myself, that was easier than playing around with these two very complicated tools). Everything was going very fast. I started last Saturday and today I can say I have a fully functional language complete with Bytecode-Compiler, Stack and Virtual Machine, the language is very similar to C++ and features nearly all C++ Datatypes. It is missing references (or pointers) and user defined types such as structs, but this will also be included the next days.

However I am not quite sure how to implement class derivation. My scripts look like that:

code:

class Character;
import class Vector3;
import class Weapon;
//Here are global variables
var Vector3 position;
var Vector3 rotation;
var Weapon pistol;

function bool SeesPlayer () {
if (Engine::CheckPlayerInViewSpace(this) == true) {
return true;
}
return false;
}

function FireWeapon() {
pistol.Fire();
}

//This function is called when the script is loaded
function Init() {
position.Set(0,0,0);
rotation.Set(0,0,0);
pistol.InitAmmo();
}

//This is the main function which is called every Frame
function DoTick() {
if (SeesPlayer() == true) {
FireWeapon();
}
}



Ok, so, this is what my scripts look like. My question is:

If I create another class derived from Character this class inherits all variables and functions form it's parent. So that's recursive, cause this parent also inherits all variables and functions of its parent and so on....
Now, should I combine all Parent-Classes together during compile time or should I first do that at load time. So, if my new class would like like that:

code:

class Monter1 extends Charakter;

function DoTick() {
//Do something other than class character does that.
}



In this case my function DoTick overrides the function of character. Well, function overriding is easy. Either during compile-time or loadtime I just have to check if the parent has a function with the same name as it's child, if so then do not load parent's function, that's easy both during compile and loadtime.

What do you think, which one would be better ??


Phillip

Share this post


Link to post
Share on other sites