Squirrel

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

SqPlus - Major update

Last post 10-09-2005, 5:31 PM by John Schultz. 5 replies.
Sort Posts: Previous Next
  •  10-05-2005, 7:20 PM 349

    SqPlus - Major update

    http://wiki.squirrel-lang.org/default.aspx/SquirrelWiki/SqPlus.html

    1. Integrated the latest remote debugger code.
    2. Added automated support for arbitrary class/struct script arguments.
    3. Changed constant() defs to use values at bind time (as opposed to addresses). Old style behavior supported with staticVar() and read-only flag.
    4. Removed global*() for class defs: static*() makes more sense, and global*() was duplicating code.
    5. Added UserPointer (void *) support to allow arbitrary objects to be passed from C/C++ to script. This differs from (2) above as the type is never directly exposed to script (for example, I use this system to pass sound effects objects to C/C++ code).
    6. Code cleaned up/simplified.
    7. Rewriting the code to support (OS) multithreaded script may be a future update. For now, changing the global VM pointer should be sufficient to handle multiple VMs (but not multithreaded). A simplification/optimization would be to remove all VM args and always use SquirrelVM::GetVMPtr(). Passing the VM to every function appears to only benefit an (OS) multithreaded script application.

    New example code (see testSqPlus2.cpp for more information):

    #define SQ_10 10
    #define SQ_E 2.71828182845904523536f
    #define SQ_PI 3.14159265358979323846264338327950288f
    #define SQ_CONST_STRING "A constant string"
          const int intConstant     = 7;
          const float floatConstant = 8.765f;
          const bool boolConstant   = true;

          SQClassDef<Vector3>("Vector3").
            var(&Vector3::x,"x").
            var(&Vector3::y,"y").
            var(&Vector3::z,"z").
            func(Vector3::Inc,"Inc").
            staticFunc(Add2,"Add2").
            staticFuncVarArgs(Add,"Add").
    #if 1
            staticVar(&Vector3::staticVar,"staticVar").
    #else
            staticVar(&Vector3::staticVar,"staticVar",VAR_ACCESS_READ_ONLY). // Use this method for a read-only var.
    #endif
            staticVar(&globalVar,"globalVar").
            constant(SQ_10,"SQ_10").
            constant(SQ_E,"SQ_E").
            constant(SQ_PI,"SQ_PI").
            constant(SQ_CONST_STRING,"SQ_CONST_STRING").
            constant((int)SQ_ENUM_TEST,"SQ_ENUM_TEST").
            constant(intConstant,"intConstant").
            constant(floatConstant,"floatConstant").
            constant(true,"boolTrue").
            constant(false,"boolFalse").
            constant(boolConstant,"boolConstant");
    #endif

          BindConstant(SQ_PI*2,"SQ_PI_2");
          BindConstant(SQ_10*2,"SQ_10_2");
          BindConstant("Global String","GLOBAL_STRING");


    John
  •  10-08-2005, 6:58 PM 353 in reply to 349

    Re: SqPlus - Major update

    Added direct class/struct var access (http://www.brightland.com/sq/SQUIRREL2_0_5_sqplus_1.zip):

    class PlayerManager {
    public:
      struct Player {
        ScriptStringVar64 name;
        void printName(void) {
          printf("Player.name = %s\n",name.s);
        }
      };
      Player playerVar; // Will be accessed directly.
      Player players[2];
      Player * GetPlayer(int player) { // Must return pointer: a returned reference will behave the same as return by value.
        return &players[player];
      }
      PlayerManager() {
        players[0].name = "Player1";
        players[1].name = "Player2";
        playerVar.name  = "PlayerVar";
      }
    } playerManager;

    DECLARE_INSTANCE_TYPE(PlayerManager)
    DECLARE_INSTANCE_TYPE(PlayerManager::Player)

    PlayerManager * getPlayerManager(void) { // Must return pointer: a returned reference will behave the same as return by value.
      return &playerManager;
    }

    //...

    //Init code:

    SQClassDef<PlayerManager::Player>("PlayerManager::Player").
      func(PlayerManager::Player::printName,"printName").
      var(&PlayerManager::Player::name,"name");

    SQClassDef<PlayerManager>("PlayerManager").
      func(PlayerManager::GetPlayer,"GetPlayer").
      var(&PlayerManager::playerVar,"playerVar");

    RegisterGlobal(getPlayerManager,"getPlayerManager");

    SquirrelObject testGetInstance = SquirrelVM::CompileBuffer("\
      local PlayerManager = getPlayerManager(); \n\
      local oPlayer = PlayerManager.GetPlayer(0); \n\
      print(typeof oPlayer); \n\
      oPlayer.printName(); \n\
      PlayerManager.playerVar.printName(); \n\
      print(PlayerManager.playerVar.name); \n\
      oPlayer = PlayerManager.playerVar; \n\
      oPlayer.name = \"New_Name\"; \n\
    ");

    // Test:

    SquirrelVM::RunScript(testGetInstance);
    printf("playerManager.playerVar.name: %s\n",playerManager.playerVar.name.s);


    If the class/struct does not need to be dereferenced in script (no var or function access), use:
    varAsUserPointer() to bind the variable, as it will be faster (no temporary OT_INSTANCE will be created for each access).


    John
  •  10-09-2005, 8:41 AM 356 in reply to 353

    Re: SqPlus - Major update

    Hey John, seems that sqplus is generating quite a bit of interest, why don't you create a page on the wiki so that there is a clear reference point for downloads/examples?

    ciao

    Alberto

  •  10-09-2005, 12:48 PM 358 in reply to 356

    Re: SqPlus - Major update

     fagiano wrote:

    Hey John, seems that sqplus is generating quite a bit of interest, why don't you create a page on the wiki so that there is a clear reference point for downloads/examples?

    ciao

    Alberto



    OK => http://wiki.squirrel-lang.org/default.aspx/SquirrelWiki/SqPlus.html

    John
  •  10-09-2005, 4:51 PM 359 in reply to 349

    Re: SqPlus - Major update

    (put into new thread) - cant delete this post
  •  10-09-2005, 5:31 PM 361 in reply to 359

    Re: SqPlus - Major update

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