static int ll_loadfunc(lua_State *L, const char *path, const char *name, int r) { void **reg = ll_register(L, path); if (*reg == NULL) *reg = ll_load(L, path, (*name == '*')); if (*reg == NULL) { return PACKAGE_ERR_LIB; /* Unable to load library. */ } else if (*name == '*') { /* Only load library into global namespace. */ lua_pushboolean(L, 1); return 0; } else { const char *sym = r ? name : mksymname(L, name, SYMPREFIX_CF); lua_CFunction f = ll_sym(L, *reg, sym); if (f) { lua_pushcfunction(L, f); return 0; } if (!r) { const char *bcdata = ll_bcsym(*reg, mksymname(L, name, SYMPREFIX_BC)); lua_pop(L, 1); if (bcdata) { if (luaL_loadbuffer(L, bcdata, ~(size_t)0, name) != 0) return PACKAGE_ERR_LOAD; return 0; } } return PACKAGE_ERR_FUNC; /* Unable to find function. */ } }
static int ll_loadfunc (lua_State *L, const char* path, const char* sym) { void** reg = ll_register(L, path); if (*reg == nullptr) *reg = ll_load(L, path); if (*reg == nullptr) return ERRLIB; /* unable to load library */ else { lua_CFunction f = ll_sym(L, *reg, sym); if (f == nullptr) return ERRFUNC; /* unable to find function */ lua_pushcfunction(L, f); return 0; /* return function */ } }
static int ll_loadfunc(lua_State *L, const char *path, const char *sym) { void **reg = ll_register(L, path); if (*reg == NULL) *reg = ll_load(L, path); if (*reg == NULL) { return PACKAGE_ERR_LIB; /* unable to load library */ } else { lua_CFunction f = ll_sym(L, *reg, sym); if (f == NULL) return PACKAGE_ERR_FUNC; /* unable to find function */ lua_pushcfunction(L, f); return 0; /* return function */ } }
static int ll_loadfunc (lua_State *L, const char *path, const char *sym) { void **reg = ll_register(L, path); if (*reg == NULL) *reg = ll_load(L, path, *sym == '*'); if (*reg == NULL) return ERRLIB; /* unable to load library */ if (*sym == '*') { /* loading only library (no function)? */ lua_pushboolean(L, 1); /* return 'true' */ return 0; /* no errors */ } else { lua_CFunction f = ll_sym(L, *reg, sym); if (f == NULL) return ERRFUNC; /* unable to find function */ lua_pushcfunction(L, f); /* else create new function */ return 0; /* no errors */ } }
static int ll_loadlib (lua_State *L) { const char *path = luaL_checkstring(L, 1); // const char *init = luaL_checkstring(L, 2); int stat; void **reg = ll_register(L, path); if (*reg == NULL) { stat = ERRLIB; /* unable to load library */ } else { stat = ERRFUNC; /* unable to find function */ } lua_pushliteral(L, DLMSG); /* error; error message is on stack top */ lua_pushnil(L); lua_insert(L, -2); lua_pushstring(L, (stat == ERRLIB) ? LIB_FAIL : "init"); return 3; /* return nil, error message, and where */ }