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

Sqplus, and arrays
Exponent
#1 Posted : Thursday, September 15, 2005 1:29:55 PM(UTC)
Rank: Member

Groups: Registered
Joined: 9/14/2005(UTC)
Posts: 23

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hello.

Okay, in Sqplus, you have the CreateArray function to create an array of a fixed size. I was wondering, is there a way to resize the array in sqplus, or am I forced to use the native squirrel functions to do this? Thanks for the help!
John Schultz
#2 Posted : Thursday, September 15, 2005 3:23:15 PM(UTC)
Rank: Member

Groups: Registered
Joined: 6/24/2005(UTC)
Posts: 241

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hi Exponent,



I added the array functions to sqPlus: I'll post an update shortly.



John
Exponent
#3 Posted : Friday, September 16, 2005 1:14:41 AM(UTC)
Rank: Member

Groups: Registered
Joined: 9/14/2005(UTC)
Posts: 23

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Sounds great, I can't wait
John Schultz
#4 Posted : Friday, September 16, 2005 2:10:09 PM(UTC)
Rank: Member

Groups: Registered
Joined: 6/24/2005(UTC)
Posts: 241

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
OK, the new version is up.



Here's the test code:



      // === BEGIN Array Tests ===



      SquirrelObject array = SquirrelVM::CreateArray(10);

      int i;

      for (i = 0; i < 10; i++) array.SetValue(i,i);

      array.ArrayAppend(123);          // int

      array.ArrayAppend(true);         // bool (must use bool and not SQBool (SQBool is treated as INT by compiler).

      array.ArrayAppend(false);        // bool (must use bool and not SQBool (SQBool is treated as INT by compiler).

      array.ArrayAppend(123.456f);     // float

      array.ArrayAppend(_T("string")); // string

      array.ArrayAppend(456);          // Will be popped and thrown away (below).



      // Pop 3 items from array:

      array.ArrayPop(SQFalse);                 // Don't retrieve the popped value (int:123).

      SquirrelObject so1 = array.ArrayPop();   // Retrieve the popped value.

      const char * val1 = so1.ToString();      // Get string.

      float val2 = array.ArrayPop().ToFloat(); // Pop and get float.

      printf("[Popped values] Val1: %s, Val2: %f\n",val1,val2);



      int startIndex = array.Len();

      array.ArrayExtend(10); // Implemented as: ArrayResize(Len()+amount).

      for (i = startIndex; i < array.Len(); i++) array.SetValue(i,i*10);

      root.SetValue("array",array);



      SquirrelObject arrayr = array.Clone(); // Get a copy as opposed to another reference.

      arrayr.ArrayReverse();

      root.SetValue("arrayr",arrayr);



      // === END Array Tests ===



      SquirrelObject define_printArray = SquirrelVM::CompileBuffer(" function printArray(name,array) { print(name+\".len() = \"+array.len()); foreach(i, v in array) if (v != null) { if (typeof v == \"bool\") v = v ? \"true\" : \"false\"; print(\"[\"+i+\"]: \"+v); } } ");

      SquirrelVM::RunScript(define_printArray);

      SquirrelObject test = SquirrelVM::CompileBuffer(" printArray(\"array\",array); printArray(\"arrayr\",arrayr); ");

      SquirrelVM::RunScript(test);





John
Exponent
#5 Posted : Friday, September 16, 2005 2:49:51 PM(UTC)
Rank: Member

Groups: Registered
Joined: 9/14/2005(UTC)
Posts: 23

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Excuse my ignorance, but where can I download the new sqplus?
John Schultz
#6 Posted : Friday, September 16, 2005 2:55:26 PM(UTC)
Rank: Member

Groups: Registered
Joined: 6/24/2005(UTC)
Posts: 241

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
[link]http://www.brightland.com/sq/SQUIRREL2_0_4_w2_sqplus.zip[/link]
Exponent
#7 Posted : Friday, September 16, 2005 4:30:29 PM(UTC)
Rank: Member

Groups: Registered
Joined: 9/14/2005(UTC)
Posts: 23

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Ah, heh, thanks!
John Schultz
#8 Posted : Friday, September 16, 2005 5:07:04 PM(UTC)
Rank: Member

Groups: Registered
Joined: 6/24/2005(UTC)
Posts: 241

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Array test output:



[Popped values] Val1: string, Val2: 123.456001

array.len() = 23

[0]: 0

[1]: 1

[2]: 2

[3]: 3

[4]: 4

[5]: 5

[6]: 6

[7]: 7

[8]: 8

[9]: 9

[10]: 123

[11]: true

[12]: false

[13]: 130

[14]: 140

[15]: 150

[16]: 160

[17]: 170

[18]: 180

[19]: 190

[20]: 200

[21]: 210

[22]: 220

arrayr.len() = 23

[0]: 220

[1]: 210

[2]: 200

[3]: 190

[4]: 180

[5]: 170

[6]: 160

[7]: 150

[8]: 140

[9]: 130

[10]: false

[11]: true

[12]: 123

[13]: 9

[14]: 8

[15]: 7

[16]: 6

[17]: 5

[18]: 4

[19]: 3

[20]: 2

[21]: 1

[22]: 0



LOL on index 6 and 8. [b][b]
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.142 seconds.