Old 01-23-2015, 02:24 PM   #1
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default Help : Basic Array and Table management in EEL

Hi !

Can someone please show a simple example of how to store a variable in a array in EEL ? and how to add / delete a variable in this same ?
and show how to call it ?
can we have multi-dimensional table ?

Thanks
X-Raym is offline   Reply With Quote
Old 01-24-2015, 02:00 AM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

I was trying to make an action to glue selected items independently, but I faced several problems.
Glue action make all selected items glued together. and there is no 'item id', just item id in tracks.

So I guess the action should be in two times.
First save the selection in multi dimensional arrays in order to be abble to recall each element one at a time.(a global array contains arrays with track ID from selected items and the item position index in this track) Then have a loop to get the array's data, select items one to one and make the action 'glue'.

Do you confirm it could be a nice way to do it ?
Can someone give me a bit of help on this ?

Thanks !
X-Raym is offline   Reply With Quote
Old 01-25-2015, 07:39 PM   #3
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

I just found the EEL stack function in the API but I don't know how to use it =/ An example will be very appreciated !
Thanks !
X-Raym is offline   Reply With Quote
Old 01-26-2015, 12:57 AM   #4
kuus0
Human being with feelings
 
Join Date: Feb 2011
Posts: 159
Default

Maybe you want something like this?
PHP Code:
max_num_columns 10;
max_num_rows 10;
n_rows 10;
ar_col_length 100// array to store row lengths
arr ar_col_length max_num_rows;
next_array arr max_num_rows max_num_columns;

// storing (add) value:

col ar_col_length[row];
// check if col < max_num_columns here
arr[row max_num_columns col] = value;
ar_col_length[row] += 1
kuus0 is offline   Reply With Quote
Old 01-26-2015, 01:07 AM   #5
kuus0
Human being with feelings
 
Join Date: Feb 2011
Posts: 159
Default

I looked at that other post and figured you could do with simpler arrays:

PHP Code:
max_num_vals 10;
n_vals 0;
ar_vals 100;
ar_vals2 ar_vals2 max_num_vals;

// add value
ar_vals[n_vals] = new_value;
n_vals += 1;

// 'pop' values

while(n_vals) (
  
value ar_vals[n_vals 1];
  
n_vals -= 1;
  
// do something with value 
); 
kuus0 is offline   Reply With Quote
Old 01-26-2015, 05:53 AM   #6
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@kuus0
Thank you a lot for your help !

I didn't understand the 3 and 4th line in your second example.
Let me recap your code with commentary to see if I am correct.

PHP Code:
max_num_vals 10// Define the maximum number of values which can be stored in our table. Needed for table declaration.
n_vals 0// Define the first index value number for our table. 
ar_vals 100// ? What for ? 
ar_vals2 ar_vals2 max_num_vals// ? don't really understand why there is a 2 here

// add value 
ar_vals[n_vals] = new_value// Add a value new_value at index n_vals in the table ar_vals
n_vals += 1// Table index incrementation

// 'pop' values 

while(n_vals) ( // ? don't really know why there is a while loop here
  
value ar_vals[n_vals 1]; get the value of the last table element and store it in a variable.
  
n_vals -= 1//substract 1 to our index
  // do something with value  
); 
It seems that EEL manage tables in a way different manner than the other languages I know, so, sorry for the beginner level question.

And other question :
Where did you learn that ?

Cheers !
X-Raym is offline   Reply With Quote
Old 01-26-2015, 06:32 AM   #7
kuus0
Human being with feelings
 
Join Date: Feb 2011
Posts: 159
Default

Check this for basic array usage:

http://forum.cockos.com/showpost.php...37&postcount=9

PHP Code:
ar_vals 100// ? What for ? 
100 is the memory address for our array ar_vals.

You could use 100[0], 100[1], ... but ar_vals[0], ar_vals[1] is saner.

ar_vals2 is there just to show you where the next array should start. You don't want multiple arrays using the same memory addresses.

And the loop is there just as an example how you could go through your stored values.
kuus0 is offline   Reply With Quote
Old 01-26-2015, 06:41 AM   #8
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

Thanks to yoy, I'll startig to understand !
I wouldn.t be able to find that alone, It's really way different than PHP for example, where we have function for declaring arrays etc... :P

Just to be sure :
The forum post link you gave me speak about the 'one big array concept in Jesusonic, but I guess it is the same thing with EEL ?
X-Raym is offline   Reply With Quote
Old 01-26-2015, 06:46 AM   #9
kuus0
Human being with feelings
 
Join Date: Feb 2011
Posts: 159
Default

Quote:
Originally Posted by X-Raym View Post
The forum post link you gave me speak about the 'one big array concept in Jesusonic, but I guess it is the same thing with EEL ?
Yes it is.

According to this http://reaper.fm/sdk/js/basiccode.php#js_basic
the size of that array is probably 2^23. I haven't tested it, though.
kuus0 is offline   Reply With Quote
Old 01-26-2015, 07:26 AM   #10
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

That should be enough for me :P

How would you get the number of elements registered in a table (if there less that the maxium) ?
(EDIT : Ok, I can retur n_vals).

For curiosity, what about stack EEL function that we can found in the ReaScript API (stack_exch...) ? It seems that there is no need to use them.

Thanks again for your patience !

Last edited by X-Raym; 01-26-2015 at 07:37 AM.
X-Raym is offline   Reply With Quote
Old 01-31-2015, 10:43 AM   #11
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 7,241
Default

I'm trying to do arrays. I have an array of items that have these values.

loop(CountSelectedMediaItems(0),
item = GetSelectedMediaItem(0, i));
#setSelectedMediaItem[i] = item;
i += 1;
)

so, debugging the array it returns these values
#setSelectedMediaItem[0]=59243488
#setSelectedMediaItem[1]=59244208
#setSelectedMediaItem[2]=59245344
#setSelectedMediaItem[3]=59246480

and at some point later in the code all array values return 2000011 except for the first [0] column of the array which retains the original stored value 59243488.

I'm not sure what is happening. any help?
heda is offline   Reply With Quote
Old 01-31-2015, 10:49 AM   #12
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

hmmm maybe you shouldn't use a global variable for your array, it is probably modified somewhere in your script.
OR
you have an other array that write over this array data (remember, there is only one global array with slots, you have to allocate "memory address" for each one to prevent any error).

I have to admit that EEL arrays is not the thing I am good at either.
X-Raym is offline   Reply With Quote
Old 01-31-2015, 10:50 AM   #13
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by X-Raym View Post

I have to admit that EEL arrays is not the thing I am good at either.
Just use Lua... (That doesn't have proper arrays either but a Lua table with a number as the key for an index is close enough. Just remember the indexing must start from 1 instead of 0...)
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 01-31-2015, 10:58 AM   #14
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@Xenakios
(so we can speak about LUA ? )

So Lua can have Arrays with Key => Value ? I would love to see that !

Any link to share to learn this language ?
I see how to use it in the api but it doesn't tell us how to write a working script :P
X-Raym is offline   Reply With Quote
Old 01-31-2015, 10:58 AM   #15
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 7,241
Default

Quote:
Originally Posted by X-Raym View Post
hmmm maybe you shouldn't use a global variable for your array, it is probably modified somewhere in your script.
OR
you have an other array that write over this array data (remember, there is only one global array with slots, you have to allocate "memory address" for each one to prevent any error).

I have to admit that EEL arrays is not the thing I am good at either.
I didn't know we have only one array space. I was trying to do a second array. I have no idea what I am doing. I surrender
heda is offline   Reply With Quote
Old 01-31-2015, 11:02 AM   #16
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@heda
Haha Totally understand.
This array management is just... well... non human friendly ^^

If it's better in Lua, I am ready to learn it. :P
X-Raym is offline   Reply With Quote
Old 01-31-2015, 11:06 AM   #17
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by X-Raym View Post
@Xenakios
(so we can speak about LUA ? )

So Lua can have Arrays with Key => Value ? I would love to see that !

Any link to share to learn this language ?
I see how to use it in the api but it doesn't tell us how to write a working script :P
Technically Lua shouldn't be discussed here but I couldn't help myself mentioning it since the topic was Eel and its painful arrays that don't make any sense.

In Lua you can do a table that acts like a number indexed array like this :
Code:
// Create empty table
my_array={};
// Put in some values, the table resizes as needed when a key in the table
// is assigned to
my_array[1]=100;
my_array[2]=400;
for i=3, 10 do
  my_array[i]=i*500;
end
The quirk to keep in mind is that my_array[0] is something bad that isn't going to work, as far as I recall for now. Since the "array" is a Lua table, you can also potentially do some weird stuff like my_array["Eel sucks"]=true; which may be useful or confusing, depending on the situation...
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 01-31-2015, 11:15 AM   #18
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@Xenakios
I will not blame you for this :P

Code:
for i=3, 10 do
  my_array[i]=i*500;
end
it seems simple but I don't understand that part. What is that 10 ?
X-Raym is offline   Reply With Quote
Old 01-31-2015, 11:21 AM   #19
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by X-Raym View Post
@Xenakios
I will not blame you for this :P

Code:
for i=3, 10 do
  my_array[i]=i*500;
end
it seems simple but I don't understand that part. What is that 10 ?
The end condition for the for-loop...(That is, the loop ends when the variable "i" has been incremented to 10.) I just threw in that for-loop as a bonus, it doesn't directly have anything to do with using the Lua tables like arrays.

All this stuff is explained in beginner Lua tutorials, which I've had to myself look up several times, as Lua has its quirks compared to C, C++ and Python...
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 01-31-2015, 11:28 AM   #20
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@Xenakios
That seems evident, know you said it.

Just find this website for Lua. Seems quite good !
X-Raym is offline   Reply With Quote
Old 01-31-2015, 12:21 PM   #21
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

Quote:
Originally Posted by Xenakios View Post
Technically Lua shouldn't be discussed here but I couldn't help myself mentioning it since the topic was Eel and its painful arrays that don't make any sense. [...]
Ehm, perhaps we should just necromance the discussion here or there.
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Banned is offline   Reply With Quote
Old 01-31-2015, 12:25 PM   #22
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@Banned
Yep, ReaLua !
But it was told to me in the pre-release discussion that new Lua integration is very different from ReaLua, and that it was not a good infos source for scripting for v5. =/
X-Raym is offline   Reply With Quote
Old 01-31-2015, 12:33 PM   #23
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 7,241
Default

Quote:
Originally Posted by X-Raym View Post
@heda
Haha Totally understand.
This array management is just... well... non human friendly ^^

If it's better in Lua, I am ready to learn it. :P
thank you for helping me to understand arrays !!! I finally did the script !! posting it now..
heda is offline   Reply With Quote
Old 01-31-2015, 12:55 PM   #24
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

Quote:
Originally Posted by X-Raym View Post
But it was told to me in the pre-release discussion that new Lua integration is very different from ReaLua, and that it was not a good infos source for scripting for v5. =/
Yes indeed. As long as we all understand that, it may serve as a good excuse to discuss Lua more generally here.
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Banned is offline   Reply With Quote
Old 01-31-2015, 01:11 PM   #25
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@heda
I can't wait to see the source code, for trying to debug this !

@Banned
That sounds like a bit rebel. I like it.
But be careful, you could be... banned
X-Raym is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:51 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.