lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi, Francisco Olarte

Thank you for your clarification.

>Source code is pretty easy to follow. Normally functions are
>registered  in src/l*lib.c.
If I understand you correctly, the functions that provided by the sources that
named as src/l*.c which are without "lib" characters are used internally by Lua,
not for the users?

Am I right?
Best regards
Sunshilong

On Sat, Oct 10, 2020 at 7:11 PM Francisco Olarte <folarte@peoplecall.com> wrote:
>
> Hi Sunshilong:
> On Sat, Oct 10, 2020 at 9:47 AM 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
> > How to locate the implementation of a specific function, e.g. string.byte?
> > I hope to dig deep in the related code snippet.
> > I would be grateful to have some help with this question.
>
> Source code is pretty easy to follow. Normally functions are
> registered  in src/l*lib.c. You can start by grepping for
> luaL_setfuncs, which is the function most normally used to register
> them, and find things like ( in 5.4.0 sources )
>
> src/lstrlib.c
> 1786:  luaL_setfuncs(L, stringmetamethods, 0);
>
> Then you can go there and see:
>
>    1761 static const luaL_Reg strlib[] = {
>    1762   {"byte", str_byte},
>    1763   {"char", str_char},
>
> And from these is just a matter of searching for it:
>
>     176 static int str_byte (lua_State *L) {
>     177   size_t l;
>     178   const char *s = luaL_checklstring(L, 1, &l);
>
> This method works generally for me when I'm curious on how a lib
> function is done.
>
> Francisco Olarte.