Preprocessing

Started by
7 comments, last by j3p 11 years, 7 months ago
Hello,

I have a few questions about possibility own built-in preprocessing to realize addition functionality.

1) I would like to add #define directive. How can I do this?
2) Is it possible to add some another preprocessor directives?
3) Is it possible to replace not-AS type to built-in type? For example from "unassigned int" to "uint".
4) Is it possible to re-declare arrays from AS-way to C-way. I mean using "int arr[5]" instead of "int[] arr(5)".

Thank you in advance.
Advertisement
1-2) One option might be ro run a C-style preprocessor on the source before giving it to AngelCode it.

You can usually configure a C or C++ compiler to stop after preprocessing and output the resulting files. You could also try a standalone preprocessor to avoid depending on a complex compiler suite.
rip-off, thanks, i got idea, so will make my own preprocessing utility. Seems, that in the same way I can solve 3-4 questions.. But, hope AngelScript will be better with this functionality due avoiding to rewrite old C-sources in AS-syntax.
4. static arrays are in to-do list.
but there are not terribly useful in most cases.
I have no intention of mimicking C/C++ syntax in every aspect with the AngelScript language. I take ideas from a lot of different programming languages, C++ is obviously a major source, but it is not the only one, and not all aspects of C++ are well suited for a scripting language.

That said, I believe it should be relatively easy to automatically translate C/C++ code into AngelScript code. If you're planning on writing your own pre-processor, then perhaps the CScriptBuilder add-on may serve as a foundation. It does some basic preprocessing already, and I'm sure you can expand it to do what you desire.

Regards,
Andreas

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

Thank you, Andreas. I've got idea and solved my problems as you said extending CScriptBuilder functionality.
As my question is somewhat related, I might as well post it here...
My question is about possibility of using HLSL preprocessor with anglescript:

1. Is it possible to specify an absolute line number instead of offsets that AddScriptSection accepts?

2. Can AddScriptSection handle "broken" code, for example if the preprocessor produced the following code:

void FloatingEffect ( ref @ r ) {
Actor @ a = cast < Actor @ > ( r ) ;
#line 20
Base::Entity::LinearVelocityLayer @ vl = a . be . GetLinearVelocityLayer ( 1 ) ;
}

This would be handled in two AddScriptSection -calls, one containing code before the #line and one containing after.
Ideally this line-directive would come after some #included code, but unfortunately the HLSL preprocessor throws them all over the place.

I already tried this, but I'm getting "unexpected end of file" -errors so I suspect that AddScriptSection doesn't like incomplete code.
I could just add the whole script as one section, but then I couldn't take advantage of the line -directives and that would be a mess...
A doomed idea or any workarounds?
Each script section must contain complete entities. Sections can refer to entities in other sections without a problem, but you cannot have half of a class or function in one section and the other half in another section.

There is currently no directive to adjust the line number like the above. It would be possible to enhance the CScriptBuilder to keep a translation table for line numbers, so that a line number reported by the script engine can be translated into the corresponding line number in the original code before the preprocessor ran.

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

Good idea, I think I'll try that.

This topic is closed to new replies.

Advertisement