static int loadfunc (lua_State *L, const char *filename, const char *modname) { const char *funcname; const char *mark; modname = luaL_gsub(L, modname, ".", LUA_OFSEP); mark = strchr(modname, *LUA_IGMARK); if (mark) { int stat; funcname = lua_pushlstring(L, modname, mark - modname); funcname = lua_pushfstring(L, LUA_POF"%s", funcname); stat = ll_loadfunc(L, filename, funcname); if (stat != ERRFUNC) return stat; modname = mark + 1; /* else go ahead and try old-style name */ } funcname = lua_pushfstring(L, LUA_POF"%s", modname); return ll_loadfunc(L, filename, funcname); }
int loader_C_luatex (lua_State *L, const char *name, const char *filename) { const char *funcname; funcname = mkfuncname(L, name); if (ll_loadfunc(L, filename, funcname,0) != 0) loaderror(L, filename); return 1; /* library loaded successfully */ }
extern "C" int loader_XCDirect (lua_State *L, const char* filename, const char* name) { const char *funcname; //const char *filename = luaL_checkstring(L, 1); //const char *name = luaL_checkstring(L, 2); DWORD dwsz; // Check existance of module LPRDATA rdPtr = XLuaGlobal::Get().GetStateByState(L)->rdList.front()->rdPtr; HANDLE hFile = rdPtr->rHo.hoAdRunHeader->rh4.rh4Mv->mvOpenHFile(filename, &dwsz, 0); if (hFile == INVALID_HANDLE_VALUE) { return 1; } rdPtr->rHo.hoAdRunHeader->rh4.rh4Mv->mvCloseHFile(hFile); // Extract + Load module char* tpath = (char*) calloc(_MAX_PATH, sizeof(char)); rdPtr->rHo.hoAdRunHeader->rh4.rh4Mv->mvGetFile(filename, tpath, 0); funcname = mkfuncname(L, name); if (ll_loadfunc(L, tpath, funcname) != 0) { free(tpath); loaderror(L, filename); return 0; } free(tpath); return 1; }
static int lj_cf_package_loader_c(lua_State *L) { const char *name = luaL_checkstring(L, 1); const char *filename = findfile(L, name, "cpath"); if (filename == NULL) return 1; /* library not found in this path */ if (ll_loadfunc(L, filename, name, 0) != 0) loaderror(L, filename); return 1; /* library loaded successfully */ }
static int loader_C (lua_State *L) { const char* funcname; const char* name = luaL_checkstring(L, 1); const char* filename = findfile(L, name, "cpath"); if (filename == nullptr) return 1; /* library not found in this path */ funcname = mkfuncname(L, name); if (ll_loadfunc(L, filename, funcname) != 0) loaderror(L, filename); return 1; /* library loaded successfully */ }
static int ll_loadlib (lua_State *L) { const char* path = luaL_checkstring(L, 1); const char* init = luaL_checkstring(L, 2); int stat = ll_loadfunc(L, path, init); if (stat == 0) /* no errors? */ return 1; /* return the loaded function */ else { /* 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 */ } }
int loader_Call_luatex (lua_State *L, const char *name, const char *filename) { const char *funcname; int stat; if (filename == NULL) return 1; /* root not found */ funcname = mkfuncname(L, name); if ((stat = ll_loadfunc(L, filename, funcname,0)) != 0) { if (stat != PACKAGE_ERR_FUNC) loaderror(L, filename); /* real error */ lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, name, filename); return 1; /* function not found */ } return 1; /* library loaded successfully */ }
static int lj_cf_package_loader_croot(lua_State *L) { const char *filename; const char *name = luaL_checkstring(L, 1); const char *p = strchr(name, '.'); int st; if (p == NULL) return 0; /* is root */ lua_pushlstring(L, name, (size_t)(p - name)); filename = findfile(L, lua_tostring(L, -1), "cpath"); if (filename == NULL) return 1; /* root not found */ if ((st = ll_loadfunc(L, filename, name, 0)) != 0) { if (st != PACKAGE_ERR_FUNC) loaderror(L, filename); /* real error */ lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, name, filename); return 1; /* function not found */ } return 1; }
static int loader_Croot (lua_State *L) { const char *funcname; const char *filename; const char *name = luaL_checkstring(L, 1); const char *p = strchr(name, '.'); int stat; if (p == NULL) return 0; /* is root */ lua_pushlstring(L, name, p - name); filename = findfile(L, lua_tostring(L, -1), "cpath"); if (filename == NULL) return 0; /* root not found */ funcname = mkfuncname(L, name); if ((stat = ll_loadfunc(L, filename, funcname)) != 0) { if (stat == ERRFUNC) return 0; /* function not found */ else loaderror(L); /* real error */ } return 1; }
extern "C" int loader_XC (lua_State *L) { const char *funcname; const char *filename; const char *name = luaL_checkstring(L, 1); filename = x_findfile(L, name, "cpath"); if (filename == NULL) return 1; /* library not found in this path */ char* tpath = (char*) calloc(_MAX_PATH, sizeof(char)); LPRDATA rdPtr = XLuaGlobal::Get().GetStateByState(L)->rdList.front()->rdPtr; rdPtr->rHo.hoAdRunHeader->rh4.rh4Mv->mvGetFile(filename, tpath, 0); funcname = mkfuncname(L, name); if (ll_loadfunc(L, tpath, funcname) != 0) { free(tpath); loaderror(L, filename); return 0; } free(tpath); return 1; }