Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Bug Reports

Reply
 
Thread Tools Display Modes
Old 05-24-2016, 03:08 PM   #1
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default Lua: "reaper.xyz is unknown"

Code:
counter = 0

function loop()
  counter = counter + 1
  reaper.ShowConsoleMsg(string.format("loop %d\n", counter))

  pcall(function()
    gfx.hello_world = 42
  end)

  if counter < 50 then
    reaper.defer(loop)
  end
end

loop()
Result:

When clicking on the "Continue" button in the error dialog, the loop() function is ran only twice, instead of 50 times:



Expected:

No error dialog at all (because of pcall), or a least it should not abort the script when clicking on the Continue button.

Last edited by cfillion; 07-19-2016 at 06:16 PM. Reason: it's partialy fixed in v5.23pre1+v5.23pre2 :D
cfillion is offline   Reply With Quote
Old 07-10-2016, 12:08 PM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

Here is a workarround (with SWS extension check)
ReaScripts-Templates/X-Raym_Check if SWS is installed and download if not.lua at master · ReaTeam/ReaScripts-Templates

The trick is to loop in reaper function table and store existing key (aka function names) in a table, and check if an extension function (no matter which one) exist in this table or not.
It doesn't return REAPER error if it doesn't exist.

EDIT: code snippet updated with new method, base don NammedCommand

Last edited by X-Raym; 07-15-2016 at 11:01 AM.
X-Raym is offline   Reply With Quote
Old 07-14-2016, 08:33 PM   #3
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

It's not a perfect workaround though. pairs(reaper) seems to be giving "ghost" functions, such as:
  • 'reaper.ov_info' is unknown
  • 'reaper.ov_pcm_total' is unknown
  • 'reaper.wave__createMetadataSource' is unknown
They are functions (type(v) == 'function'), but when called they throw the dreaded non-catchable "is unknown" error.

Code:
for k,v in pairs(reaper) do
  reaper.ShowConsoleMsg(string.format("%s is a %s\n", k, type(v)))
end

-- this prints "function"
reaper.ShowConsoleMsg(string.format("%s\n", type(reaper.ov_read_float)))

-- but this crashes the script with the fatal "is unknown" error
reaper.ov_read_float()

Last edited by cfillion; 07-14-2016 at 08:57 PM.
cfillion is offline   Reply With Quote
Old 07-15-2016, 11:01 AM   #4
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

I update the code snippet with a Workaround by Heda that works with NamedCommand instead of looping reaper table

way more efficient and reliable.
X-Raym is offline   Reply With Quote
Old 07-15-2016, 01:10 PM   #5
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

@X-Raym Nice trick for checking SWS's presence.

Summary of the bugs/annoyances so far:
  1. "reaper.xyz is unknown" error always stop the script execution when using reaper.defer() and clicking on the "Continue" button when the IDE is closed
  2. "reaper.xyz is unknown" error cannot be caught by lua's pcall() unlike other lua/reascript errors
  3. reaper['inexistant'] behavior is inconsistent with lua table behavior: it throws an error instead of returning nil EDIT: This one is fixed in REAPER 5.23pre1!
  4. pairs(reaper) gives ghost (uncallable and undocumented) functions EDIT: Fixed in v5.23pre2!

(These all affect my interactive reascript script, I guess it's kind of an edge case...)

Last edited by cfillion; 11-23-2016 at 05:23 PM. Reason: better english, trying to be clearer
cfillion is offline   Reply With Quote
Old 07-15-2016, 02:20 PM   #6
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,749
Default

This is all fairly complicated under the hood. However, it should be easy for us to add an API function API_exists("function_name"), does that get you where you want to be?
schwa is offline   Reply With Quote
Old 07-15-2016, 06:59 PM   #7
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,749
Default

On second thought, we'll do both. The next build will add APIExists("function_name"), and also treat reaper.* as a generic table with respect to getting and setting elements. So reaper.somefunction will be nil if somefunction() is not defined in the particular version of REAPER that is running the script. As a side effect you'll be able to set reaper.whatever="foo" and that will work too, though that's somewhat pointless.
schwa is offline   Reply With Quote
Old 07-16-2016, 12:02 PM   #8
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Awesome, thank you! Will gfx also be changed? Currently it has the same "is unknown" behavior and non-function indexes – x, w, mouse_cap etc – are not listed by pairs(gfx). EDIT: it is

Last edited by cfillion; 07-16-2016 at 04:27 PM.
cfillion is offline   Reply With Quote
Old 10-24-2021, 11:25 AM   #9
Flaneurette
Human being with feelings
 
Join Date: Dec 2016
Posts: 373
Default

Quote:
Originally Posted by schwa View Post
On second thought, we'll do both. The next build will add APIExists("function_name"), and also treat reaper.* as a generic table with respect to getting and setting elements. So reaper.somefunction will be nil if somefunction() is not defined in the particular version of REAPER that is running the script. As a side effect you'll be able to set reaper.whatever="foo" and that will work too, though that's somewhat pointless.
Can it enumerate SWS functions as well?
Flaneurette is offline   Reply With Quote
Old 10-24-2021, 11:38 AM   #10
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Quote:
Originally Posted by Flaneurette View Post
Can it enumerate SWS functions as well?
Yes, extension functions too.
cfillion is offline   Reply With Quote
Old 10-24-2021, 12:50 PM   #11
Flaneurette
Human being with feelings
 
Join Date: Dec 2016
Posts: 373
Default

Quote:
Originally Posted by cfillion View Post
Yes, extension functions too.

Tried to query CF_GetSWSVersion and it gave back: 0.
Flaneurette is offline   Reply With Quote
Old 10-24-2021, 01:19 PM   #12
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

With the latest SWS (2.12.1)? It works here:

cfillion is offline   Reply With Quote
Old 10-24-2021, 02:32 PM   #13
Flaneurette
Human being with feelings
 
Join Date: Dec 2016
Posts: 373
Default

Quote:
Originally Posted by cfillion View Post
With the latest SWS (2.12.1)? It works here:
Yes, it works now. Forgot to add the function as string.
Code:
RPR_ShowConsoleMsg(RPR_APIExists("CF_GetSWSVersion"))
instead of:
Code:
RPR_ShowConsoleMsg(RPR_APIExists(CF_GetSWSVersion))
Last one gave zero.
Flaneurette 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 12:16 PM.


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