** 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
| 381 | ** errors, return an error code and an error message in the stack. |
| 382 | */ |
| 383 | static int lookforfunc (lua_State *L, const char *path, const char *sym) { |
| 384 | void *reg = checkclib(L, path); /* check loaded C libraries */ |
| 385 | if (reg == NULL) { /* must load library? */ |
| 386 | reg = lsys_load(L, path, *sym == '*'); /* global symbols if 'sym'=='*' */ |
| 387 | if (reg == NULL) return ERRLIB; /* unable to load library */ |
| 388 | addtoclib(L, path, reg); |
| 389 | } |
| 390 | if (*sym == '*') { /* loading only library (no function)? */ |
| 391 | lua_pushboolean(L, 1); /* return 'true' */ |
| 392 | return 0; /* no errors */ |
| 393 | } |
| 394 | else { |
| 395 | lua_CFunction f = lsys_sym(L, reg, sym); |
| 396 | if (f == NULL) |
| 397 | return ERRFUNC; /* unable to find function */ |
| 398 | lua_pushcfunction(L, f); /* else create new function */ |
| 399 | return 0; /* no errors */ |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | |
| 404 | static int ll_loadlib (lua_State *L) { |
no test coverage detected