lua_find C API?

81 views
Skip to first unread message

Rett Berg

unread,
Nov 17, 2025, 12:28:02 AM (11 days ago) Nov 17
to lu...@googlegroups.com
I'm thinking of writing a bytearray C extension and wanted to support find. Is there a reason the function which supports string.find isn't in the C API? Is it possible it could be added?

Thanks!
- Rett

bil til

unread,
Nov 17, 2025, 2:06:26 AM (11 days ago) Nov 17
to lu...@googlegroups.com
You mean "pimping up" your C "function realm" with a C function
similar to string.find?

... but the string.find in strlib.c is quite clear, see the function
"str_find" there?

Rett Berg

unread,
Nov 17, 2025, 7:44:43 PM (10 days ago) Nov 17
to lua-l
Sorry, I should have been more clear.


has "str_find_aux" which works off of the lua_State.

I'm asking if it could be slightly refactored to call a C function which is also exported for C extensions to use

// Find the pattern p in string s.
lua_Match lua_find(
  char* s, int s_len,   // subject
  char* p, int p_len); // pattern

And... I think I'm seeing why -- it's because that lua_Match object would be relatively complicated because of match groups. While it should be possible to define a lua_Match_next_group function or something to recursively extract the groups, I'm sure that wasn't seen as a high priority.

Thanks everyone, I answered my own question.

- Rett
Reply all
Reply to author
Forward
0 new messages