Squirrel

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

SqPlus Enums

Last post 07-03-2008, 2:20 PM by AndiNo. 3 replies.
Sort Posts: Previous Next
  •  06-30-2008, 9:37 AM 2597

    SqPlus Enums

    I'm having some problems compiling my code using SqPlus enums. Whenever I use DECLARE_ENUM_TYPE the compiler gives me several errors. I even tried to compile the example code:
    class VariousMembers {
    public:
        VariousMembers(char ch_ = 0,
                       short sh_ = 0,
                       const SQChar *str_ = _SC("default val"))

                : m_ch(ch_),
                  m_sh(sh_),
                  m_str(str_) {}

        enum Mode {Mode1, Mode2};
        int FuncWithEnumArg(Mode m) {return int(m);}

        char m_ch;
        short m_sh;
        const SQChar *m_str;    // Treated like a string by SqPlus get/set
    };

    DECLARE_ENUM_TYPE(VariousMembers::Mode);
    DECLARE_INSTANCE_TYPE(VariousMembers);


    Whenever I use DECLARE_ENUM_TYPE these errors pop up (there are 42 currently, only some here):
    obj\Debug\bullet.o:: In function `ZN6SqPlus5MatchENS_11TypeWrapperIN14VariousMembers4ModeEEEP4SQVMi':
    D:\Programmieren\SMR\sqmanager.h:51: multiple definition of `SqPlus::Match(SqPlus::TypeWrapper<VariousMembers::Mode>, SQVM*, int)'
    obj\Debug\SMRApp.o:D:\Programmieren\SMR\sqmanager.h:51: first defined here
    obj\Debug\bullet.o:: In function `ZN6SqPlus3GetENS_11TypeWrapperIN14VariousMembers4ModeEEEP4SQVMi':
    D:\Programmieren\SMR\sqmanager.h:46: multiple definition of `SqPlus::Get(SqPlus::TypeWrapper<VariousMembers::Mode>, SQVM*, int)'
    obj\Debug\SMRApp.o:D:\Programmieren\SMR\sqmanager.h:46: first defined here
    obj\Debug\bullet.o:: In function `ZN6SqPlus4PushEP4SQVMN14VariousMembers4ModeE':
    D:\Programmieren\SMR\sqmanager.h:8: multiple definition of `SqPlus::Push(SQVM*, VariousMembers::Mode)'
    obj\Debug\SMRApp.o:D:\Programmieren\SMR\sqmanager.h:8: first defined here
    obj\Debug\game.o:: In function `ZN6SqPlus5MatchENS_11TypeWrapperIN14VariousMembers4ModeEEEP4SQVMi':
    D:\Programmieren\SMR\sqmanager.h:51: multiple definition of `SqPlus::Match(SqPlus::TypeWrapper<VariousMembers::Mode>, SQVM*, int)'
    obj\Debug\SMRApp.o:D:\Programmieren\SMR\sqmanager.h:51: first defined here


    What am I doing wrong?

    And a second question: If I get the enums to work, do I have to bind every single (C++)enum to Squirrel with
    SQClassDef<VariousMembers>(_SC("VariousMembers"))
            .enumInt(VariousMembers::Mode1, _SC("Mode1"))
            .enumInt(VariousMembers::Mode2, _SC("Mode2"))
    etc...? It would be easier if I could just use DECLARE_ENUM_TYPE to declare my enum to Squirrel and wouldn't have to bind about 144 enum values by hand (keyboard keys in this case)...
  •  07-03-2008, 5:21 AM 2602 in reply to 2597

    Re: SqPlus Enums

    I guess I'm missing just a small thing that prevents me from compiling this. Please give me a hint so I can finish binding my code to Squirrel. I know there are some SQ pros here :P

    edit: maybe I should mention that I'm using the SqPlus-Review version from here:
    http://squirrel-lang.org/forums/thread/2504.aspx
  •  07-03-2008, 1:33 PM 2603 in reply to 2597

    Re: SqPlus Enums

    Hello,

    I pasted your source into one of my .cpp files and it compiles just fine.

    I think the problem  is that you have this binding in a .h file and that you're
    including this header multiple times.

    Bindings should really go in a .cpp file that the compiler reads precisely one time.


    The second question (binding enum values):

    If you want to use names instead of numbers on the Squirrel side, then you do
    have to bind each name using SqPlus. If you're fine using decimal numbers in
    the script (65 instead of KEY_A), then you can skip that.

    (The C++ side doesn't care if you bind each enum value or not, but the script
    developer might care).

    Regards
    // ATS.


  •  07-03-2008, 2:20 PM 2604 in reply to 2603

    Re: SqPlus Enums

    I tried copying the code into different files to see if there was a difference, but I didn't just copy the DECLARE_ENUM_TYPE because in many (or all) example files the DECLAREs were written directly after the class/enum declaration, so this was my fault :)
    Thanks for the answer, looks like I have some work to do ;)
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems