Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6569981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:41:57+00:00 2026-05-25T14:41:57+00:00

The HsLua examples on the Haskell Wiki are broken (dostring and dofile are not

  • 0

The HsLua examples on the Haskell Wiki are broken (dostring and dofile are not defined). Looks like the API has changed since the examples were written.

However I have been trying to modify the examples to match the current API and not getting much success. Here’s a program that should really work!

main = do
    l <- Lua.newstate
    Lua.openlibs l
    Lua.loadfile l "configfile.lua"
    [name,pwd] <- Lua.callfunc l "getuserpwd" "mail.google.com"
    putStrLn name
    Lua.close l

However, this doesn’t even compile, giving me this strange error message –

No instance for (Lua.StackValue [String])
  arising from a use of `Lua.callfunc'
Possible fix:
  add an instance declaration for (Lua.StackValue [String])
In a stmt of a 'do' expression:
    [name, pwd] <- Lua.callfunc l "getuserpwd" "mail.google.com"
In the expression:
  do { l <- Lua.newstate;
       Lua.openlibs l;
       Lua.loadfile l "configfile.lua";
       [name, pwd] <- Lua.callfunc l "getuserpwd" "mail.google.com";
       .... }
In an equation for `main':
    main
      = do { l <- Lua.newstate;
             Lua.openlibs l;
             Lua.loadfile l "configfile.lua";
             .... }

While the content of the file configfile.lua probably doesn’t matter (because the haskell code doesn’t even compile), it is as below (same as on the wiki page) –

function getuserpwd (site)
  local cookies = { ["www.ibm.com"] = {"joe", "secret"}
                  , ["www.sun.com"] = {"hoe", "another secret"}
                  }
  if cookies[site] then
    return cookies[site]
  elseif site:match("[.]google[.]com$") then
    return {"boss", "boss"}
  else
    return { os.getenv("USER") or "God"
           , os.getenv("PWD")  or "dontdisturb" }
  end
end

Could someone please provide me with a working example of Haskell->Lua and Lua->Haskell calls?

Edit

Okay I changed the type of the return value to a String (from the earlier array of String), and that program does compile! However it now fails at runtime. Here’s the modified program –

main = do
    l <- Lua.newstate
    Lua.openlibs l
    Lua.loadfile l "configfile.lua"
    Lua.callfunc l "getuserpwd" "mail.google.com" >>= putStrLn
    Lua.close l

And here’s configfile.lua –

function getuserpwd (site)
  return "boss"
end

And the runtime error message is as follows –

**** Exception: user error (attempt to call a nil value)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:41:57+00:00Added an answer on May 25, 2026 at 2:41 pm

    You have to execute loaded Lua chunk prior to calling any functions:

    main = do
        l <- Lua.newstate
        Lua.openlibs l
        Lua.loadfile l "configfile.lua"
        Lua.call l 0 0
        Lua.callfunc l "getuserpwd" "mail.google.com" >>= putStrLn
        Lua.close l
    

    Method dofile was a wrapper for loadfile and call, I don’t know reasons for removing it.

    Edit.
    This code calls function that returns table and iterates over it. It is based on this traversal example. I am not sure how to do it via callfunc.

    import qualified Scripting.Lua as Lua
    import Control.Monad.Loops
    import Data.Maybe
    
    print_table l = do
        Lua.pushnil l
        whileM_ (Lua.next l 1) (Lua.tostring l (-1) >>= putStrLn >> Lua.pop l 1)
    
    main = do
      l <- Lua.newstate
      Lua.openlibs l
      Lua.loadfile l "configfile.lua"
      Lua.call l 0 0
      Lua.getglobal l "getuserpwd"
      Lua.pushstring l "mail.google.com"
      Lua.call l 1 (-1) -- calls function without Haskell extensions
      print_table l
      Lua.close l
    

    It turns out that HsLua implementation is a very simple wrapper and there are no suitable Haskell bindings for Lua tables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why the following fallback for IE color: red; does not work ? In IE7,
This works: a { color: hsla(0,100%,50%,0.2) } And this does not: img { color:
I like checking CSS validity. It makes things work better. However, a stylesheet I'm
I'm using a PHP script that dynamically generates transparent PNGs for use as CSS
I have the following structure: <div class=feed-item style=position:relative; id=feed-611 onmouseover=showDelete() onmouseout=hideDelete()> <div class=feed-avatar> AVATAR
I have a nested ordered list with this structure <ol> <li> <span>A</span> <ol class=childol>
Lets say, we have string ABCAD, now we need to iterate through all possible
I am using the nice style of the wizard mentioned in this blog but
Here's an example mixin: =border($alpha: 0.2) 1px solid hsla(0, 0, 0, $alpha) I want
I am developing a tool which will convert html colors between maximum any format

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.