YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Enums in bytecode scripts
Mephisto
#1 Posted : Sunday, March 13, 2016 10:20:04 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/5/2010(UTC)
Posts: 20
Location: Roslindale, MA

Thanks: 9 times
Was thanked: 2 time(s) in 2 post(s)
Not sure if this is a bug or confusion on my part, but I have a .nut file with just enumerations in it:

Code:

enum CreateMode
{
    Standard,
    Quick
}

enum ConnectMenu
{
    Server,
    Port,
    Connect
}

// etc.



And then I have other .nut files that use these enums. This all works fine until I compile all of the files to bytecode using 'sq -o enums.cnut -c enums.nut'. When I execute the bytecode scripts, I receive errors that the enums do not exist:

Quote:

SCRIPT ERROR
the index 'CreateMode' does not exist


If I drop the plain text version of the script into its place, everything executes as expected without error.

What am I missing this time, or is this a legitimate bug? I have read the documentation, but may be once again missing the relevance of a passage. I don't see anything about special rules with enums or constants in bytecode.
fagiano
#2 Posted : Wednesday, March 16, 2016 1:14:45 PM(UTC)
Rank: Advanced Member

Groups: Registered, Administrators
Joined: 6/11/2005(UTC)
Posts: 1,054

Thanks: 0 times
Was thanked: 77 time(s) in 59 post(s)
It is the expected behavior. enums and constants only exists at compile time. So, if you compile a file declaring enums againt "VM A" the enums are added to "VM A". All subsequent files compiled against "VM A" will see the enums. Now, if you destroy "VM A", create "VM B" and compile a file against "VM B" no enums will present. The solution is to create a VM and the compiles all the files you care about against it. enums are simply serialized as integers literals, the don't really "exsist" at runtime.

I hope it makes sense
ciao
Alberto
Follow me on Twitter @squirrellang
Anton
#3 Posted : Wednesday, August 3, 2016 8:01:57 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/3/2015(UTC)
Posts: 2

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
I find this issue very annoying as well.
There is a common case when you use `dofile()` as an `include` directive in your scripts to introduce declarations from other scripts in your file.

So you just can not use constants and enums included this way.
I cleary understand why this is so but this is not cool.

Maybe we should have `import` keyword in Squirrel to include scripts at compile time?

Or should constants used this way be resolved at runtime?
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.144 seconds.