Jump to content
  • Advertisement
  • entries
    437
  • comments
    1000
  • views
    337287

GMScript consts

Sign in to follow this  
evolutional

119 views

I've been looking at adding 'const' support to GM Script as it's not as easy as it seems. Right now a user can easily overwrite one of the variables that you set up for your nice API for them to use.

The first thought about adding this support comes down to end-user syntax. We have a couple of options for this; the first is to declare consts similar to how you would in C++:-

global const = ;

This is intuitive to C++ programmers, but in the end I believe it'd be much harder to implement and can cause issues when using them in tables eg:

mytable = table( const = );

It's just plain dirty.

The second option is to provide a 'const' type which itself holds a value and will enforce how it's allowed to be changed. So now we're looking at a syntax such as:

global = const( );

I believe this option sits better with GMScript itself and is easier to use in normal coding.

mytable = table( = const( ) );
or
myint = const( 50 );

I've decided to make an extension to GMScript to add in this const support, mainly because I feel as if I NEED it for GMGX. Maybe not right now, but when it goes public I don't want people to make stupid errors which kills things for them.

So the first port of call is to go through and add support for a native const type. This is harder than it sounds as the basic types are EVERYWHERE in GMScript. Here's my plan:

- Upgrade the Scanner
- Upgrade the lexxer
- Add a native gmConstObject class and wire it up to gmMachine
- Add in support for gmConstObject assignment in the gmVariable
- Add in the native binding for the new const object
- Update the code generator to recognise the new type
- Add in a new bytecode instruction
- Update the gmThread execute function to validate assignment operations on local const objects
- Update the gmTableObject 'Set' method to verify assignment operations on table-bound const objects

There's probably a bunch more, but as you can see it's hardly a trivial task. We have an interesting dilemma from this - we only want to be able to update const variables from the native API that GM gives us, however this same API is used by GM internally (at least for table variables). I'll find a way...

[grin]
Sign in to follow this  


1 Comment


Recommended Comments

Quote:
as you can see it's hardly a trivial task

No Kidding!

Good luck with it though - it'll be a useful feature if you get it working.

Jack

Share this comment


Link to comment

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
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!