|
|
|
05-24-2016, 03:08 PM
|
#1
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,967
|
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
|
|
|
07-10-2016, 12:08 PM
|
#2
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
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.
|
|
|
07-14-2016, 08:33 PM
|
#3
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,967
|
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.
|
|
|
07-15-2016, 11:01 AM
|
#4
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
I update the code snippet with a Workaround by Heda that works with NamedCommand instead of looping reaper table
way more efficient and reliable.
|
|
|
07-15-2016, 01:10 PM
|
#5
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,967
|
@X-Raym Nice trick for checking SWS's presence.
Summary of the bugs/annoyances so far:
- "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
- "reaper.xyz is unknown" error cannot be caught by lua's pcall() unlike other lua/reascript errors
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!
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
|
|
|
07-15-2016, 02:20 PM
|
#6
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 15,821
|
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?
|
|
|
07-15-2016, 06:59 PM
|
#7
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 15,821
|
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.
|
|
|
07-16-2016, 12:02 PM
|
#8
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,967
|
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.
|
|
|
10-24-2021, 11:25 AM
|
#9
|
Human being with feelings
Join Date: Dec 2016
Posts: 373
|
Quote:
Originally Posted by schwa
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?
|
|
|
10-24-2021, 11:38 AM
|
#10
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,967
|
Quote:
Originally Posted by Flaneurette
Can it enumerate SWS functions as well?
|
Yes, extension functions too.
|
|
|
10-24-2021, 12:50 PM
|
#11
|
Human being with feelings
Join Date: Dec 2016
Posts: 373
|
Quote:
Originally Posted by cfillion
Yes, extension functions too.
|
Tried to query CF_GetSWSVersion and it gave back: 0.
|
|
|
10-24-2021, 01:19 PM
|
#12
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,967
|
With the latest SWS (2.12.1)? It works here:
|
|
|
10-24-2021, 02:32 PM
|
#13
|
Human being with feelings
Join Date: Dec 2016
Posts: 373
|
Quote:
Originally Posted by cfillion
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.
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 06:16 PM.
|