Sign in to follow this  
Hardguy

Custom keyword and object type flag (solved, code attached)

Recommended Posts

I currently have a system that saves all the data in class and now I wanted to add some basic system that can be used to set a property as not saved. My currently implementation is basically one of name syntax, if the member varaible name starts with "_" (eg "_myVar") it is NOT saved otherwise it is. This not feel that good and instead I would like to do something like: [code]class cMyClass { nosave float mNotSavedVariable }[/code] Where "nosave" is a custom keyword. I would then like to do something like: [code]for(int i=0; i< apObject->GetPropertyCount(); ++i) { int lPropTypeId = apObject->GetPropertyTypeId(i); ... }[/code] and if the property is declared with "nosave" I can see this by checking a flag in lPropTypeId Is something like this possible?

Share this post


Link to post
Share on other sites
Everything is possible :)

However, this sounds like a perfect match for the metadata functionality implemented in the [url="http://www.angelcode.com/angelscript/sdk/docs/manual/doc_addon_build.html"]CScriptBuilder add-on[/url]. The implementation needs to be expanded to also deal with class properties, but I think you'll be able to do that quite easily.

PS. I enjoyed the presentations of your script support over at [url="http://frictionalgames.blogspot.com/"]Frictional Games[/url]. They even gave me a few ideas for future features.

Share this post


Link to post
Share on other sites
Oki cool, did not think about that feature as a possible way to solve it!

How could I make the end result look like? Something like

[code]class cMyClass {
[nosave] float mNotSavedVariable
}[/code]

or do I need to do something like:

[code]
[data
nosave: mNotSavedVariable
]
class cMyClass {
float mNotSavedVariable
}[/code]

From what I read [url="http://www.angelcode.com/angelscript/sdk/docs/manual/doc_addon_build.html"]here[/url] it seems like the second example is what I can do, but would be nice to know before I get at it.


Glad you enjoyed the videos and that they gave some ideas! I will probably do more as I want to show of the saving a bit more.

Share this post


Link to post
Share on other sites
I believe what WitchLord is saying is that ScriptBuilder out of the box gives you the second one, but you could modify it to achieve the first one.

Share this post


Link to post
Share on other sites
[quote name='immortius' timestamp='1310788820' post='4835886']
I believe what WitchLord is saying is that ScriptBuilder out of the box gives you the second one, but you could modify it to achieve the first one.
[/quote]

Ah yeah, reread and that is what he said. Silly me.

Thanks for pointing out!

Share this post


Link to post
Share on other sites
I suggested something like this already. Having a keyword defined right before a variable makes the code a lot more readable as opposed to having all keywords located at the top of a class definition. I also dislike the use of square brackets in front of variables to wrap some keywords. It just looks weird and non-C++ish.

While the metadata approach does offer some flexibility, its rather cumbersome *imho*. You're also required to use two separate parsers (one for metadata, another for scripts), and thus two separate databases for keywords. For this reason I suggested my approach [url=http://www.gamedev.net/topic/591552-idea-user-defined-keywords/page__p__591552]here[/url].

Share this post


Link to post
Share on other sites
The use of square brackets is entirely up to the application developer. I like it for the fact that it is something that is not really part of the script, and the square brackets show that. Kind of like IDL commonly used in C++. The implementation in the CScriptBuilder is just an example, and just shows how it can be done, but not everyone wants to do it like that, which is why I keep this feature in the add-on rather than as part of the core engine.

The discussion in the other thread did lead to some interesting ideas that I plan on taking a closer look at for a future release. Especially the part where the parser would provide callbacks to the application engine to allow notifications and even modifications on the fly. This would be especially handy for the metadata parsing.

Share this post


Link to post
Share on other sites
Yeah, I understand. I thought it was a relevant topic, so I linked it. The first post in that thread was only a preliminary suggestion. I thought I would put the feature in the core because it already has a parser that I would simply extend.

What I forgot to suggest was to wrap the whole implementation into a #ifdef directive, so that a user could choose whether or not to have certain features included in the core library at compile time by simply adding lines like "#define AS_USER_KEYWORDS 1" to as_config.h ... kind of like how compiling a linux kernel works. Though I see you prefer to use addons for this purpose.

Share this post


Link to post
Share on other sites
Finally got about working on this and just finished adding support for variables in classes. Attaching the changed code here in case anybody is interested. The code is not that nice, but does the trick.

Would be very interested in hearing about any strange things or things that can be made better!

Share this post


Link to post
Share on other sites
Just took a look at your modified builder and it looks pretty solid. I'll give it a test drive when I get a chance and tell you how it works. Metadata in class methods is so much cleaner than class metadata, annd would work perfectly with my Qt style signals and slots implementation I am working on for my engine.

Share this post


Link to post
Share on other sites
Great. I took a quick look at it and it looks good.

I'll take a closer look and add some regression tests for the changes to include in the SDK as soon as possible.

Regards,
Andreas

Share this post


Link to post
Share on other sites
I see you have a method for class variables, but what about class functions? Looks like you got a start on it, but I don't see anything in the code that suggests that it's finding metadata for class functions.

Share this post


Link to post
Share on other sites
[quote name='_orm_' timestamp='1314204851' post='4853277']
I see you have a method for class variables, but what about class functions? Looks like you got a start on it, but I don't see anything in the code that suggests that it's finding metadata for class functions.
[/quote]

You are correct. That is not yet implemented, since I had no need for it, but should be quite simple to add. Just a matter of adding a few lines where the global functions are added.

Share this post


Link to post
Share on other sites
I've finally checked in this improvement to the CScriptBuilder add-on. Except for a few minor tweaks and fixes I kept it pretty much as-is.

You'll find the updated version in revision 954.


Thanks a lot for the contribution.

Share this post


Link to post
Share on other sites
Found a small error in the new code

[code]

if( currentClass == "" )
pos = SkipStatement(pos);
else
pos += len;
[/code]

should be:



[code]

if( currentClass != "" )
pos = SkipStatement(pos);
else
pos += len;
[/code]

Else it will not skip functions in classes properly.

Share this post


Link to post
Share on other sites
Another thing I found. Need to add:

[code]

//Skip any white spaces in case meta data follows:
t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len);
while(t == asTC_COMMENT || t == asTC_WHITESPACE) {
pos += len;
t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len);
}
[/code]

At the end of the section that checks handles the start of class, ie the one that starts with:
[code]if( modifiedScript.substr(pos,len) == "class" )
{[/code]

Sorry for spamming changes, but seemed so small that was not worth to upload the entire code.

Share this post


Link to post
Share on other sites
You were right. The changes were needed, however as I applied them I saw that the code could be cleaned up a bit so I ended up doing it a bit differently.

[url="http://angelscript.svn.sourceforge.net/viewvc/angelscript/trunk/sdk/add_on/scriptbuilder/scriptbuilder.cpp?r1=954&r2=958"]Here's the diff for revision 958[/url].

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this