Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jbhoot opened this issue Sep 12, 2024 · 4 comments
Open

Comments

@jbhoot
Copy link
Contributor

jbhoot commented Sep 12, 2024

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
Copy link
Contributor Author

jbhoot commented Sep 12, 2024

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
Copy link
Contributor Author

jbhoot commented Sep 13, 2024

Ah. lua-ml does not implement it.

@dmbaturin
Copy link
Collaborator

Was gsub in PUC-Rio Lua 2.5?

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

@jbhoot
Copy link
Contributor Author

jbhoot commented Sep 13, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants