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 lj_cf_package_loader_preload(lua_State *L) { const char *name = luaL_checkstring(L, 1); lua_getfield(L, LUA_ENVIRONINDEX, "preload"); if (!lua_istable(L, -1)) luaL_error(L, LUA_QL("package.preload") " must be a table"); lua_getfield(L, -1, name); if (lua_isnil(L, -1)) { /* Not found? */ const char *bcname = mksymname(L, name, SYMPREFIX_BC); const char *bcdata = ll_bcsym(NULL, bcname); if (bcdata == NULL || luaL_loadbuffer(L, bcdata, ~(size_t)0, name) != 0) lua_pushfstring(L, "\n\tno field package.preload['%s']", name); } return 1; }
void footer(stream outstr, string callname, string options) { char name[MAXLINE]; if (*callname) strcpy(name,callname); else strcpy(name,"nemomain"); mksymname(name, options); fprintf(outstr," NULL,\n};\n\n"); fprintf(outstr,"string usage=\"%s\";\n\n", (e_usage ? e_usage : "NEMO program with unknown intent")); fprintf(outstr,"extern void %s(void);\n",name); fprintf(outstr,"void nemo_main()\n{\n"); fprintf(outstr," %s();\n}\n",name); }