I'm having trouble posting my C++ example with '\' characters in here, but basically it's just multiline with a backslash at the end of each line... Scott
Multiline Strings
We've planning on switching over from using GameMonkey to AngelScript. Our primary use is a C-style code stitcher for interactive graph-based shader development tool. So we work alot with string, but seems AngelScript ( despite having 12+ major features we want over GameMonkey ) does not seem to handle multi-line strings, even with usage of '\' like so...
In GameMonkey we do it like this...
TemplateCode =
"
float HLSLFunc( float a )
{
return a;
}
";
In C++ I ahve to do it this way...
CString TemplateCode = " \\ float HLSLFunc( float a )\ { \ return a;\ } \";
Which is still ugly for us... So is there any good way to do this in AngelScript?
Thanks!
AngelScript supports what's sometimes called heredoc strings. You use triple quote chars for this, e.g.:
I hope you'll enjoy using AngelScript. I'm continuously working on improving it even more, so don't hesitate to let me know which features you'd like to see implemented next.
Regards,
Andreas
TemplateCode = """float HLSLFunc( float a ){return a;}""";
I hope you'll enjoy using AngelScript. I'm continuously working on improving it even more, so don't hesitate to let me know which features you'd like to see implemented next.
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
I guess I could always put in my own helper macro like so...
string Code = STRING
[
float HLSLFunction( float a )
{
return a;
}
];
Right before compiling the script, I would expand everything between STRING[...] to something the compiler likes by looking for line ends and replacing like so...
string Code =
"float HLSLFunction( float a )\n" +
"{\n" +
"\treturn a;\n;" +
"}\n";
Should work... But please let me know if there is any simpler way :)
string Code = STRING
[
float HLSLFunction( float a )
{
return a;
}
];
Right before compiling the script, I would expand everything between STRING[...] to something the compiler likes by looking for line ends and replacing like so...
string Code =
"float HLSLFunction( float a )\n" +
"{\n" +
"\treturn a;\n;" +
"}\n";
Should work... But please let me know if there is any simpler way :)
I guess you were writing your last post while I answered your question ;)
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
I think AngelScript is great, stumbled on it today and I'm already ripping out GameMonkey as we speak since the syntax is practically the same, but AS just does so much more in terms of language functionality.
One thing that would be sweet, but I'm sure it's not doable would be to allow switch statements to take in non literals, maybe call the switch something else and have it dynamic and act somewhat like a cascade of if/elseif/else statements... I'm thinking mostly in terms of using it for string, like...
string Entry = "Head";
switch ( Entry )
{
case "Head":
// do something
break;
case "Tail":
// do something
break;
default:
// do something
}
I know there must be some performance / design reason why this is not feasible, but would make our stuff alot more readible, using a bunch of if/elseif/else statements isn't as readible...
Also, one last question... In our current scripting setup, users are able to type in as many arguments as they want into functions and it's up to the app's function callback to throw errors if say there are too many or not enough arguments...
so something like this...
float AddPort_FloatInput( string Name, int Dimension = 4, float x = 0, float y = 0, float z = 0, float w = 0 );
Is there any way to handle something similar where the user need only input the first argument?
Thanks for the quick reply, much appreciated!
Scott
One thing that would be sweet, but I'm sure it's not doable would be to allow switch statements to take in non literals, maybe call the switch something else and have it dynamic and act somewhat like a cascade of if/elseif/else statements... I'm thinking mostly in terms of using it for string, like...
string Entry = "Head";
switch ( Entry )
{
case "Head":
// do something
break;
case "Tail":
// do something
break;
default:
// do something
}
I know there must be some performance / design reason why this is not feasible, but would make our stuff alot more readible, using a bunch of if/elseif/else statements isn't as readible...
Also, one last question... In our current scripting setup, users are able to type in as many arguments as they want into functions and it's up to the app's function callback to throw errors if say there are too many or not enough arguments...
so something like this...
float AddPort_FloatInput( string Name, int Dimension = 4, float x = 0, float y = 0, float z = 0, float w = 0 );
Is there any way to handle something similar where the user need only input the first argument?
Thanks for the quick reply, much appreciated!
Scott
default arguments for functions is one of the things i'm waiting for... since looong time :)
Does AngelCode handle global or member functions with the same name just different amount of arguments?
Thanks,
Scott
Thanks,
Scott
switch cases that allow strings is something that I'd like to implement in a future version. It should be possible to make the performance quite good by ordering the strings and then using binary search to find the correct case.
default arguments for functions is also something that is on the to-do list. But it's quite low priority at the moment as there are many other features that are more importart (such as inheritance).
AngelScript fully supports function overloads, just like C++. So you can definitely have functions with the same name but with different argument counts.
I'm pleased to hear that AngelScript has more features than GameMonkey. I hear a lot about GameMonkey but never had the time to check it out myself.
Regards,
Andreas
default arguments for functions is also something that is on the to-do list. But it's quite low priority at the moment as there are many other features that are more importart (such as inheritance).
AngelScript fully supports function overloads, just like C++. So you can definitely have functions with the same name but with different argument counts.
I'm pleased to hear that AngelScript has more features than GameMonkey. I hear a lot about GameMonkey but never had the time to check it out myself.
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement