Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 06-03-2020, 01:07 PM   #1
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,458
Default EEL : any library of string functions similar to lua? / match help

Hello!

Is there any library of string functions that are similar to what is available in lua? I remember that in the pre-lua era somebody has made some, but can't remember who and can't find the thread.

Furthermore, can someone explain me how the match works in eel? For example:
Code:
match("test","This is a test string",#result);
I expected this to match the word test and store it in #result. But it doesn't work? Why?

This matches "This is a ":
Code:
match("%s*test%s","This is a test string",#result);
No idea why! But this does not work! :
Code:
match("%s*test","This is a test string",#result);

And this matches "This is a test s" :
Code:
match("%s*t%s","This is a test string",#result);
I can't understand how it works at all...
__________________
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; 06-03-2020 at 01:13 PM.
amagalma is online now   Reply With Quote
Old 08-22-2020, 09:50 AM   #2
Hypex
Human being with feelings
 
Join Date: Mar 2015
Location: Australia
Posts: 453
Default

It kind of works like scanf() in C. It uses pattern matching. So it it's like a Linux bash command line as well I suppose. Or more like. But it accepts both formats. To match your test try this:
Code:
match("*test*","This is a test string",#result);

See bottom of page here. There's a few C-ish string functions. But direct searching of a string in strings looks to be missing. So match() is needed.


https://www.reaper.fm/sdk/js/strings.php#js_strings
Hypex is offline   Reply With Quote
Old 08-24-2020, 03:20 PM   #3
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,458
Default

Quote:
Originally Posted by Hypex View Post
Code:
match("*test*","This is a test string",#result);

Thanks for responding! Unfortunately this does not match the word "test" or anything else. #result is empty

Edit. This seems to work:
Code:
match("*test*","This is a test string",#result) == 1 & #result = "test";
But still seems quite complicated... Any link with a good explanation of how scanf() in C works?
__________________
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; 08-24-2020 at 03:28 PM.
amagalma is online now   Reply With Quote
Old 08-26-2020, 01:52 AM   #4
Hypex
Human being with feelings
 
Join Date: Mar 2015
Location: Australia
Posts: 453
Default

Quote:
Originally Posted by amagalma View Post
Thanks for responding! Unfortunately this does not match the word "test" or anything else. #result is empty

Oops sorry I made a copypasta mistake. Actually I thought the extra parameter should return an error. But it take extra ones and doesn't really explain what it would do. This should work better:
Code:
match("*test*","This is a test string") ? printf("Test passed\n")


Quote:
Edit. This seems to work:
Code:
match("*test*","This is a test string",#result) == 1 & #result = "test";
But still seems quite complicated... Any link with a good explanation of how scanf() in C works?

Yes it looks complicated. EEL does make some things easier compared to other code like Python or LUA. This would be an example but it's hard to see without real example code. Because EEL is more traditional than OOP you can call functions directly but in other OOP languages you must use the reaper class prefixed to each call which just looks annoying. Compare with language calls to GetUserInputs().

Try this example I just made up, lol. :-D
Code:
function main()(
match("*test*","This is a test string") ? printf("Test passed\n") : printf("Test failed\n");
match("*sex*","This is a test string") ? printf("Test passed\n") : printf("Test failed\n");
printf("%d\n",match("*blah*", "this string has the word blah in it"));
);

main();
I find here to be a good guide sometimes. Though it does go into detail. It might not all apply to match() but has some similar patterns.


http://www.cplusplus.com/reference/cstdio/scanf/

Last edited by Hypex; 08-26-2020 at 03:26 AM.
Hypex is offline   Reply With Quote
Old 08-26-2020, 01:59 AM   #5
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,793
Default

Code:
match("*test*","This is a test string",#result) == 1 & #result = "test";
Using "==" returns a one or a zero (aka true or false), This does not seem to make much sense without either storing same or using "?" for a decision.
The resulting value of the expression #result = "test" is the string "test" (or in fact the number of that string) which does not make much sense with "&".

-Michael

Last edited by mschnell; 08-26-2020 at 10:28 PM.
mschnell 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 10:25 AM.


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