View Single Post
Old 05-28-2020, 05:07 AM   #1271
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,458
Default

A small test:
Code:
array = reaper.new_array({25,"hello",12,-7})

-- making a copy
array_address = reaper.JS_Window_AddressFromHandle( array )
copy_of_array = reaper.JS_Window_HandleFromAddress( array_address )
-- in the IDE it can be seen that they refer to same object

-- BUT...
array_sz = array.get_alloc() -- = 4
-- copy_of_array_sz = copy_of_array.get_alloc() -- doesn't work
-- we get "attempt to index a userdata value" error

retval, buf = reaper.JS_String( array, 0, 1000 ) -- ???
first_entry = reaper.JS_Double( array, 1 ) -- returns 25! works!
second_entry = reaper.JS_Double( array, 2 ) -- returns 0 instead of "hello"

-- let's try with the copy
copy_retval, copy_buf = reaper.JS_String( copy_of_array, 0, 1000 ) -- ???
copy_first_entry = reaper.JS_Double( copy_of_array, 1 ) -- returns 25! works too!!
copy_second_entry = reaper.JS_Double( copy_of_array, 2 ) -- returns 0 instead of "hello"

How can it work with strings? As JS_Double seems to return only numbers and JS_String doesn't seem to return anything useful.. Furthermore, the handle we get is to the same object(array = copy_of_array) but copy_of_array does not behave like an array (see above). This is what happens with lua tables too but doesn't happen with the rest of reaper objects (items, takes, tracks etc). How can we overcome this?
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

Last edited by amagalma; 05-28-2020 at 05:25 AM.
amagalma is offline   Reply With Quote