PataphysicalSociety / soupault

Static website generator based on HTML element tree rewriting
https://soupault.app
MIT License
379 stars 18 forks source link

`gsub()` function missing in Lua even when Lua 2.5 manual documents it #73

Open jbhoot opened 2 months ago

jbhoot commented 2 months ago

I want to convert the text of a tag element into a url path: Firefox add-on -> firefox-add-on.

Using the Lua 2.5 manual, I wrote this transformation: collection_path = gsub(strlower(collection_text), " ", "-")

But, soupault gives an error:

[INFO] Processing widget populate-collection-link on page site/2022/box-sizing.html
[ERROR] Could not process page site/2022/box-sizing.html: Lua code execution failed:
Runtime error: string library does not implement gsub
Stack trace:
`error' fallback (OCaml)
main of dostring('collection_links = HTML.select(page, config["selector"])
loc...') defined in file dostring('collection_links = HTML.select(page, config["selector"])
loc...')

of which the statement of import is: Runtime error: string library does not implement gsub

But Lua 2.5 manual documents it.

Any clue on what's going on?

jbhoot commented 2 months ago

In case it helps anyone else, I wrote the following function as an alternative that is applicable for my specific use-case:

function make_collection_path(collection_text)
  -- collection_path = gsub(strlower(collection_text), " ", "-")
  local char_idx = 1
  local collection_path = ""
  while char_idx <= strlen(collection_text) do
    local currchar = strlower(strsub(collection_text, char_idx, char_idx))
    if currchar == " " then
      collection_path = collection_path .. "-"
    else
      collection_path = collection_path .. currchar
    end
    char_idx = char_idx + 1
  end
  return collection_path
end

I am still interested in knowing what happened to gsub.

jbhoot commented 2 months ago

Ah. lua-ml does not implement it.

dmbaturin commented 2 months ago

Was gsub in PUC-Rio Lua 2.5?

You can use https://soupault.app/reference-manual/#Regex.replace_all

jbhoot commented 2 months ago

You can use https://soupault.app/reference-manual/#Regex.replace_all

Thank you!

Was gsub in PUC-Rio Lua 2.5?

Not sure about that. But its documented in the Lua 2.5 reference manual linked to in the soupault reference manual.