Add a LVContainerTransform for interaction between koreader and crengine - #2477
Add a LVContainerTransform for interaction between koreader and crengine#2477pawanjay176 wants to merge 2 commits into
Conversation
|
Can you ask your AI to add more comments, especially for the Lua stack interactions ? Lines 536 to 636 in 7aace42 |
| virtual LVStreamRef OpenStream(const lChar32 * fname, lvopen_mode_t mode) | ||
| { | ||
| if (!fname) | ||
| return LVStreamRef(); | ||
|
|
||
| if (mode == LVOM_READ) { | ||
| LVStreamRef transformed = openTransformedEntry(lString32(fname)); | ||
| if (!transformed.isNull()) | ||
| return transformed; | ||
| } | ||
|
|
||
| return _container->OpenStream(fname, mode); | ||
| } |
There was a problem hiding this comment.
I'd like it (and similar) as condensed as:
virtual LVStreamRef OpenStream(const lChar32 * fname, lvopen_mode_t mode) {
if (!fname)
return LVStreamRef();
if (mode == LVOM_READ) {
LVStreamRef transformed = openTransformedEntry(lString32(fname));
if (!transformed.isNull())
return transformed;
}
return _container->OpenStream(fname, mode);
}| ldomDocument *dom_doc; | ||
| } CreDocument; | ||
|
|
||
| class LVContainerTransform : public LVContainer |
There was a problem hiding this comment.
Add some introduction comment, what it is for, that it is not used by KOReader but available to plugins that would like to do xyz, what it allows, etc...
| static int loadEpubWithEntryTransform(lua_State *L) { | ||
| CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); | ||
| const char *file_name = luaL_checkstring(L, 2); | ||
| luaL_checktype(L, 3, LUA_TTABLE); | ||
| bool only_metadata = false; | ||
| if (lua_isboolean(L, 4)) { | ||
| only_metadata = lua_toboolean(L, 4); | ||
| } | ||
|
|
||
| lString32 file_name32 = LocalToUnicode(lString8(file_name)); |
There was a problem hiding this comment.
Add some introduction comment, what it is for, that it is not used by KOReader but available to plugins that would like to do xyz, what it allows, etc...
Document (with a comment on each line checking one arg) what the provided arguments are expected to be (as it's not used by KOReader, hard to guess what this table at 3 should be).
| lua_pushvalue(L, 3); | ||
| int transform_ref = luaL_ref(L, LUA_REGISTRYINDEX); | ||
| LVContainerRef container(new LVContainerTransform(L, transform_ref, archive)); |
There was a problem hiding this comment.
Is that our arg 3 ? Explain what it is and how it will be used.
Really, without comments, I can't understand any of the magic :)
|
Apologies, got busy at my day job. Will update these as soon as I can! |
Related to koreader/koreader#15649
Add a wrapper
LVContainerTransformwrapper that allows koreader to provide replacement bytes for individual EPUB entries.Exposes
loadEpubWithEntryTransformfunction to be used in koreader. The transform object needs to provide the following interface:{ transformEntry = function(self, path) -- return replacement bytes, or nil to use the original entry end }Disclosure: Used AI assistance for the
openTransformedEntryfunction. I don't have deep understanding of the lua C api.This change is