MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / lookforfunc

Function lookforfunc

3rd/lua-5.4.3/src/loadlib.c:390–408  ·  view source on GitHub ↗

** Look for a C function named 'sym' in a dynamically loaded library ** 'path'. ** First, check whether the library is already loaded; if not, try ** to load it. ** Then, if 'sym' is '*', return true (as library has been loaded). ** Otherwise, look for symbol 'sym' in the library and push a ** C function with that symbol. ** Return 0 and 'true' or a function in the stack; in case of ** errors, ret

Source from the content-addressed store, hash-verified

388** errors, return an error code and an error message in the stack.
389*/
390static int lookforfunc (lua_State *L, const char *path, const char *sym) {
391 void *reg = checkclib(L, path); /* check loaded C libraries */
392 if (reg == NULL) { /* must load library? */
393 reg = lsys_load(L, path, *sym == '*'); /* global symbols if 'sym'=='*' */
394 if (reg == NULL) return ERRLIB; /* unable to load library */
395 addtoclib(L, path, reg);
396 }
397 if (*sym == '*') { /* loading only library (no function)? */
398 lua_pushboolean(L, 1); /* return 'true' */
399 return 0; /* no errors */
400 }
401 else {
402 lua_CFunction f = lsys_sym(L, reg, sym);
403 if (f == NULL)
404 return ERRFUNC; /* unable to find function */
405 lua_pushcfunction(L, f); /* else create new function */
406 return 0; /* no errors */
407 }
408}
409
410
411static int ll_loadlib (lua_State *L) {

Callers 2

ll_loadlibFunction · 0.85
loadfuncFunction · 0.85

Calls 5

checkclibFunction · 0.85
lsys_loadFunction · 0.85
addtoclibFunction · 0.85
lua_pushbooleanFunction · 0.85
lsys_symFunction · 0.85

Tested by

no test coverage detected