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: 1,005
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 online now   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: 3,906
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: 1,005
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 online now   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: 3,906
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: 1,005
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 online now   Reply With Quote
Old 07-15-2016, 02:20 PM   #6
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 9,043
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: 9,043
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: 1,005
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 online now   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 07:47 PM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.