🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Language proposal - require keyword

Started by
1 comment, last by WitchLord 4 years, 7 months ago

Hello all!

I recently switched from old way - including parent object files into derived class, even though they were marked as shared - to defining externals. So previously I had:


-- foo.as
shared abstract class Foo
{
}

-- bar.as
#include "foo.as"
shared class Bar: Foo
{
}
  

It caused some problems because every final module was littered by previous modules, line numbers in exceptions would not match and so on. Now I have it like this:


-- bar.as
external shared class Foo;

shared class Bar: Foo
{
}

But if the derived class uses some other classes from previous modules, it all has to be typed as 'external' or cause syntax errors. With some deeper hierarchy it may be a lot of boilerplate. I was thinking how to automate it while keeping a bit more explicit (don't want complete magic under the hood). My suggestion is to introduce a special keyword 'require':


-- bar.as
require "foo.as"

shared class Bar: Foo
{
}

This would be equivalent to iterating over all shared entities in foo.h (and also its own requires) and automatically externalling them for current module. 

Another way would be some sort of "export" keyword in the files that name some kind of "shared module" entity, so instead of require "foo.as" we could write require Foo; and it would know what it means as long as foo.as was compiled earlier. 

Do you think having such one-line require for a given file rather than having to specify all externals used by given file by hand would be useful? 

For now I will probably introduce some #pragma that may do something like the above, but I thought maybe there is some idea already in progress that would make the usage of shared entites a bit more convenient?

 


Where are we and when are we and who are we?
How many people in how many places at how many times?
Advertisement

I can't say I've anything planned in this regard. But it does sound like a good idea. 

In my to-do list I have a related item: ‘export’ and ‘import’ , but it doesn't address the issue of 'requiring' multiple shared entities with a single line of code.

I'd like to take a look at your implementation of the #pragma directive once it is finished. That could probably be included as a builder add-on as a preprocessor directive #require.

 

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement