Enums?
Can I youse enums and wich method does declare them to the vm? or should i use const int instead??
p.s: I''m very happy that you set up this forum
In order to solicit help effectively, one needs to supply far more specific questions. Perhaps you could specify what language you are using, and what you are trying to accomplish with it.
No hard feelings of course, just trying to help
Henry
No hard feelings of course, just trying to help
Henry
I guess ''const int'' is better, or enums should function the same way const int should work. cos i would like to use it as ints for the system function that i pass the labels to.
Jayanth.K
Raptor Entertainment Pvt. Ltd.
Jayanth.K
Raptor Entertainment Pvt. Ltd.
You can use the enums in your C source code, but not in the actual script as far as I know. You would need a bunch of cont ints there. So it doesn''t really matter what you use, you still have to cast them to something else if you want to modify them.
PS: Henners, we are talking about AngelScript. Visit the AngelCode website for more info: http://www.angelcode.com
PS: Henners, we are talking about AngelScript. Visit the AngelCode website for more info: http://www.angelcode.com
Agreed, I have tried enums with no success in scripts.
I think the real problem is that there is no way to register them, I don''t see why the engine itself wouldn''t support them.
How about a RegisterEnumType() method in a later release?
nihlist
I think the real problem is that there is no way to register them, I don''t see why the engine itself wouldn''t support them.
How about a RegisterEnumType() method in a later release?
nihlist
Anything is possible
What exactly is it that you want from an enum type in the scripting languge?
Do you want to be able to declare enums in the scripts? Do you want to pass enums to script functions? Or perhaps you wish to declare a type that can hold integer values but nothing else?
Tell me more about how you would use the enums and I''ll see what I can do to include support for them.
www.AngelCode.com - game development and more...
AngelScript - free scripting library
What exactly is it that you want from an enum type in the scripting languge?
Do you want to be able to declare enums in the scripts? Do you want to pass enums to script functions? Or perhaps you wish to declare a type that can hold integer values but nothing else?
Tell me more about how you would use the enums and I''ll see what I can do to include support for them.
www.AngelCode.com - game development and more...
AngelScript - free scripting library
I''d like to "register" the enum and simply work tih it
example (i declared an enum MyE {arm = 0, leg, hand} foo; )
so that i can write (in AS):
if (foo = leg) ...;
and it to pass it as param it would be useful too,
but it could be done with cast too
example (i declared an enum MyE {arm = 0, leg, hand} foo; )
so that i can write (in AS):
if (foo = leg) ...;
and it to pass it as param it would be useful too,
but it could be done with cast too
It''s not a perfect solution but for now you could do the following:
const char scriptEnums[] =
"const int arm = 0;\n"
"const int leg = 1;\n"
"const int hand = 2;\n";
Then add this string to the engine before building your dynamically loaded scripts:
engine->AddScriptSection("scriptfile.as", loadedScript, sizeLoadedScript);
engine->AddScriptSection("enums", scriptEnums, sizeof(scriptEnums));
engine->Build();
Having a function for automatically register enum constants is not possible, I think. The only way is to have a precompiler parse the enum declaration from the C++ file and generate code that register each enumerated constant for you.
www.AngelCode.com - game development and more...
AngelScript - free scripting library
const char scriptEnums[] =
"const int arm = 0;\n"
"const int leg = 1;\n"
"const int hand = 2;\n";
Then add this string to the engine before building your dynamically loaded scripts:
engine->AddScriptSection("scriptfile.as", loadedScript, sizeLoadedScript);
engine->AddScriptSection("enums", scriptEnums, sizeof(scriptEnums));
engine->Build();
Having a function for automatically register enum constants is not possible, I think. The only way is to have a precompiler parse the enum declaration from the C++ file and generate code that register each enumerated constant for you.
www.AngelCode.com - game development and more...
AngelScript - free scripting library
Thats a certainly a workable solution to my issues with enums.
In my previous post I was thinking of a:
RegisterEnumType(const char * enumName, int elementCount, const char ** elements)
With AS friendly inputs...
You would have to store the enums in a map type structure caching their int equivalents and preprocess the script files replacing these for ints, or handle unknown types by extending the parser.cpp IsRealType() and IsDataType().
The real work would be validating name collisions etc on addition of a new enum type.
Thinking about it, it is really worth it when constant ints either added as a script section or included in a script file would do just as well?
Sorry for the long post, but has anyone toyed with the thought of supporting script include directives for file based scripts?
If this was standardized, it would perhaps simplify the creation of large scripting implementations? Any thoughts?
nihlist
[edited by - nihlist on March 11, 2004 8:15:04 AM]
In my previous post I was thinking of a:
RegisterEnumType(const char * enumName, int elementCount, const char ** elements)
With AS friendly inputs...
You would have to store the enums in a map type structure caching their int equivalents and preprocess the script files replacing these for ints, or handle unknown types by extending the parser.cpp IsRealType() and IsDataType().
The real work would be validating name collisions etc on addition of a new enum type.
Thinking about it, it is really worth it when constant ints either added as a script section or included in a script file would do just as well?
Sorry for the long post, but has anyone toyed with the thought of supporting script include directives for file based scripts?
If this was standardized, it would perhaps simplify the creation of large scripting implementations? Any thoughts?
nihlist
[edited by - nihlist on March 11, 2004 8:15:04 AM]
I think that for now I will not add a method for registering enum types, the extra script section should be good enough.
To have an #include directive with AngelScript, a pre-processor can be run on the scripts before adding them to AngelScript. The preprocessor would then scan for #include directives with extra filenames to include. It would also substitute two first characters of the lines with "//" to form a comment so that the AngelScript compiler doesn''t complain. It should be rather easy to write a pre-processor for this case.
AngelScript will not have native support for any #include directives, because AngelScript doesn''t have any resources for reading from the disk (and will not).
www.AngelCode.com - game development and more...
AngelScript - free scripting library
To have an #include directive with AngelScript, a pre-processor can be run on the scripts before adding them to AngelScript. The preprocessor would then scan for #include directives with extra filenames to include. It would also substitute two first characters of the lines with "//" to form a comment so that the AngelScript compiler doesn''t complain. It should be rather easy to write a pre-processor for this case.
AngelScript will not have native support for any #include directives, because AngelScript doesn''t have any resources for reading from the disk (and will not).
www.AngelCode.com - game development and more...
AngelScript - free scripting library
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement