Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function "find" doesn't work #37

Open
OdoctorG opened this issue Aug 8, 2021 · 1 comment
Open

Function "find" doesn't work #37

OdoctorG opened this issue Aug 8, 2021 · 1 comment

Comments

@OdoctorG
Copy link

OdoctorG commented Aug 8, 2021

The builtin function "find" doesnt seem to work, atleast not in the try brat online editor.

Code:
"amogus".find "gus"

Ouput:

/home/brat/brat/core/core.lua:2184: attempt to call upvalue 'block' (a table value)
stack traceback:
/home/brat/brat/core/core.lua: in function 'block'
/home/brat/brat/core/core.lua:4440: in function 'each'
/home/brat/brat/core/core.lua:2189: in function '_m__temp1_find'
[string "string"]:41: in function '_m__temp3_run_underparsed'
[string "string"]:209: in function <[string "string"]:12>
stack traceback:
[string "string"]:336: in main chunk
[C]: in function 'xpcall'
/home/brat/brat/core/core.lua:1304: in function 'protect'
/home/brat/brat/bin/brat:137: in function 'run_string'
/home/brat/brat/bin/brat:162: in main chunk
[C]: at 0x5650922ed5b0

Interestingly .include? works but not find

@presidentbeef
Copy link
Owner

So... string.find has apparently never matched the documentation (the code is 8-9 years old). It's actually called find_first. You can see the mismatch here: https://github.com/presidentbeef/brat/blob/main/core/core.lua#L4910-L4924

string.find is from enumerable.find which takes a function as an argument: https://github.com/presidentbeef/brat/blob/main/core/core.lua#L2176-L2196

And apparently that isn't documented, either! 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants