Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Virtual functions


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 meink   Members   -  Reputation: 133

Like
Likes
Like

Posted 12 May 2004 - 03:36 PM

Virtual functions and derived classes aren''t supported in AngelScript, but I''m curious to know what sort of workarounds people are using. I''ve set my class up so you can register new derived classes in script (http://noreality.net/files/programming/astest.zip - An old proof of concept that outlines the idea), and I''ve expanded this in my engine so that you can migrate the derived class into C++, but the AS code still uses the same interface. I''ll get around to making that into an example file soon. Is this the method that most people are using? Are other people doing things like this? I was thinking about perhaps writing it up into a tutorial... - Xavier

Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3264

Like
Likes
Like

Posted 13 May 2004 - 04:23 AM

A tutorial would be excellent. If you want I can host it on my site, or if you prefer I''ll only put a link to it.

I''ll check out your solution when I get the time.

I have plans to support virtual functions natively, but it is still quite far down on the todo list.

__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library - Tower - free puzzle game

#3 Andreas Jonsson   Moderators   -  Reputation: 3264

Like
Likes
Like

Posted 13 May 2004 - 07:23 AM

I checked out the code. It is a very good example that clearly shows how things can be done. It is basically how I imagined AngelScript would be used.

I would put a comment in the code for Item::collidePlayer() that it can be optimized by storing the function ID in a lookup tables so that GetFunctionIDByName() doesn''t have to be called every time. Also, it might be a good idea to use some kind of pooling for contexts, so that you don''t have to create and release them each time they will be called. If each call to Prepare() uses the same stackSize the context reuses the memory it previously allocated, thus saving some more time.

I must say that I misunderstood you when you mentioned virtual functions earlier. I thought you meant that AngelScript would call virtual C++ class methods and allow polymorphism. This is what I plan to support in the future.

__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library - Tower - free puzzle game

#4 meink   Members   -  Reputation: 133

Like
Likes
Like

Posted 14 May 2004 - 01:27 AM

Yeah, I added many of those things you mentioned into my updated version (which I''ll be using for the tutorial).

For calling virtual functions from AS, I thought of having a static member function that calls this->function(). If the function was overridden in C++ it would be called, other wise the base implementation would dispatch the code to the AS defined function. Haven''t tested it though. I''ll check it out next week - I don''t have my comp for the weekend

- Xavier

#5 Andreas Jonsson   Moderators   -  Reputation: 3264

Like
Likes
Like

Posted 15 May 2004 - 05:22 AM

I look forward to read your tutorial.

__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library - Tower - free puzzle game

#6 meink   Members   -  Reputation: 133

Like
Likes
Like

Posted 16 May 2004 - 09:01 PM

http://noreality.net/as-polymorphism.zip

First draft of "Polymorphism in Angelscript". I''m hoping this is actually what polymorphism is - I''m a little sketchy on definitions - otherwise I''m going to have to change the title :S

I left a few things out, which I''ve mentioned at the end. I thought it would be better to focus on the core idea, and leave the rest as an exercise for the reader (or a later tutorial...)

I''m thinking of submitting to the gamedev scripting section, and would appreciate any feedback. I''m not exactly an expert writer...

- Xavier

#7 AndyMan   Members   -  Reputation: 148

Like
Likes
Like

Posted 19 May 2004 - 07:12 PM

I''ve written a precompiler which reads through your header files and generated a cpp file which registers all the variables and functions in all the classes/globally. If there''s enough demand I''ll try to make it a bit easier to use and make it available - it''s currently in a state where only I can use it.

One extra thing it does is make wrapper functions for all the ctors & dtors. If I was wanting to use polymorphism, I probably would have got the precompiler to generate non-virtual wrappers for all the virtual functions. As inheritence is still on the way, it''s unlikely that many people are useing virtual functions with AS.


#8 Andreas Jonsson   Moderators   -  Reputation: 3264

Like
Likes
Like

Posted 20 May 2004 - 03:35 AM

meink:

I read the tutorial now and I thought it was very good. I especially liked the way you solved dynamic properties for the CItem class, I hadn''t thought about that before.

Of course, at a later time AngelScript will support declaration of structs so it should no longer be necessary to do it like that.

I suggest you write what version of AngelScript you wrote the tutorial for as things may change in future versions.

AndyMan:

You know people would be interested in seeing a pre-compiler that helps with the configuration of the engine. If you are short on time (like me) maybe you could release it as it is so that others can improve upon it, or learn from it and write their own pre-compilers.

__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library - Tower - free puzzle game

#9 wade182   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 May 2004 - 01:49 PM

quote:
Original post by WitchLord
AndyMan:

You know people would be interested in seeing a pre-compiler that helps with the configuration of the engine. If you are short on time (like me) maybe you could release it as it is so that others can improve upon it, or learn from it and write their own pre-compilers.


Someone might look into writing a new backend for SWIG.

SWIG is a popular C++ wrapper generator that supports lots of scripting languages. It can even handle wrapping templates, etc.

No idea what is involved with writing a new backend, though.

-Wade





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS