Old 08-15-2018, 09:16 AM   #1
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
Default Q: Best way to "find" in an EEL ReaSscript?

Given the lack of a "find()" function in EEL2 I found a function by argitoth and made a few mods:

Code:
function find_string (Pneedle, Phaystack, Pstartpos)
local (i Lfoundpos LlenS LlenT)
(
    Lfoundpos = -1;
    i = Pstartpos;
    LlenS = strlen(Phaystack);
    LlenT = strlen(Pneedle);
    while(i < LlenS && Lfoundpos < 0) (
        strcmp(Pneedle,strcpy_substr(#, Phaystack, i, LlenT)) ? Lfoundpos = -1 
                                                                                : Lfoundpos = i;
        i+=1;
    );
Lfoundpos; 
);
Can you improve this, especially for CPU usage? I want to plough through a TrackStateChunk!

I was tripped up by strcmp() for a while as it returns 0 if the strings match (counter-intuitive, or what?).

I try to make most local variable start with L to make them easier to find in the IDE variable list (just comment out the local lines when debugging).
__________________
DarkStar ... interesting, if true. . . . Inspired by ...

Last edited by DarkStar; 08-16-2018 at 01:30 AM.
DarkStar is offline   Reply With Quote
Old 08-15-2018, 10:33 AM   #2
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

What about using match to get everything up to and including the search term ("+hello" I think?), and then findpos would be the length of the returned string minus "hello"?
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 08-17-2018, 02:49 AM   #3
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
Default

That might do it - I'll have a go.
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar 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 11:37 AM.


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