Squirrel

The programming language
Welcome to Squirrel Sign in | Join | Help
in Search

Does Squirrel do enums?

Last post 12-11-2006, 6:21 AM by Gersen. 4 replies.
Sort Posts: Previous Next
  •  11-18-2006, 9:04 PM 1447

    Does Squirrel do enums?

     If not, can they be emulated?
  •  11-19-2006, 9:54 AM 1451 in reply to 1447

    Re: Does Squirrel do enums?

    No they are not supported,

    In my project we simply use global tables like this:

    GUIEvent = {
     Clicked = 1,
     Resized = 2,
     MouseMove = 3,
     ...
    }

     

    Alberto

  •  11-19-2006, 3:46 PM 1455 in reply to 1451

    Re: Does Squirrel do enums?

    Makes sense and that is what I ended up doing, works just as well so you are right, why bother with another construct when it serves no advantage?

    Good job again for your design, Squirrel as a language is just wonderful. I just wish the tools were a bit more refined.
  •  12-10-2006, 8:47 PM 1620 in reply to 1451

    Re: Does Squirrel do enums?

    fagiano:

    GUIEvent = {
     Clicked = 1,
     Resized = 2,
     MouseMove = 3,
     ...
    }



    This doesn't seem to work. You say that you are using a global table, but this doesn't seem to follow the global format. As far as I can tell, it should be something more like this:

    GUIEvent <- {
     Clicked = 1,
     Resized = 2,
     MouseMove = 3,
     ...
    }

    This seems to work fine for the individual script that it's declared in, but any attempts to use this value from another script or from within C++ do not work. The docs fall short of useful examples here IMO. How should this be accessed from each? Is this considered to be part of the root table after it is executed?

    This DOES NOT work:

    const SquirrelObject rt = SquirrelVM::GetRootTable();
    int value = rt.GetInt("GUIEvent.Resized");

    'value' will be set to 0 every time. What am I doing wrong?

  •  12-11-2006, 6:21 AM 1621 in reply to 1620

    Re: Does Squirrel do enums?

    juggernaut:

    This DOES NOT work:

    const SquirrelObject rt = SquirrelVM::GetRootTable();
    int value = rt.GetInt("GUIEvent.Resized");

    'value' will be set to 0 every time. What am I doing wrong?

    You skipped one step, try that instead :


    const SquirrelObject rt = SquirrelVM::GetRootTable();
    SquirrelObject key = rt.GetValue(_T("GUIEvent"));
    int Value = key.GetInt(_T("Resized"));

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems