
Hi all, I'm having some issues calling Lua functions from Haskell. I have the following in "Haskell2Lua.lua": function hello () return "hello world" end And my Haskell file "Haskell2Lua.hs" looks like this: import qualified Scripting.Lua as Lua main = do l <- Lua.newstate Lua.openlibs l succ <- Lua.loadfile l "/Haskell2Lua.lua" print succ Lua.callproc l "hello" "" Lua.close l When I compile and run this file I get: 0 Haskell2Lua: user error (attempt to call a nil value) I have tried some variations on calling the function including: Lua.callproc l "hello" Lua.callfunc l "hello" Lua.callfunc l "hello" "" I know the Lua bridge is working because the following works: Lua.callproc l "print" "Hello from Lua" Any help is appreciated! -deech

Change this: succ <- Lua.loadfile l "/Haskell2Lua.lua" into succ <- Lua.loadfile l "Haskell2Lua.lua" Note that 0 at the beginning says there was an error loading a script. I should make it an exception I guess... -- Gracjan

I did that, the slash is a typo. I was looking at the Lua reference manual
and it says that lua_loadfile uses lua_load[1] which outputs 0 if
successful.
Appreciate the quick response.
-deech
[1] http://www.lua.org/manual/5.1/manual.html#lua_load
On Sat, Oct 23, 2010 at 2:49 AM, Gracjan Polak
Change this:
succ <- Lua.loadfile l "/Haskell2Lua.lua"
into
succ <- Lua.loadfile l "Haskell2Lua.lua"
Note that 0 at the beginning says there was an error loading a script.
I should make it an exception I guess...
-- Gracjan
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hi Aditya, The problem is not that the file was not loaded, but that in Lua, loading a file only loads it and does not execute it; Lua is a "dynamic" language, by which I mean that definitions are created through execution. Attached is a simple example, note that there is no proper error checking - you probably want to check the results rather than pattern matching against constants. Thanks, Claude On 23/10/10 03:21, aditya siram wrote:
Hi all, I'm having some issues calling Lua functions from Haskell. I have the following in "Haskell2Lua.lua": function hello () return "hello world" end
And my Haskell file "Haskell2Lua.hs" looks like this: import qualified Scripting.Lua as Lua
main = do
l<- Lua.newstate
Lua.openlibs l
succ<- Lua.loadfile l "/Haskell2Lua.lua"
print succ
Lua.callproc l "hello" ""
Lua.close l
When I compile and run this file I get: 0 Haskell2Lua: user error (attempt to call a nil value)
I have tried some variations on calling the function including: Lua.callproc l "hello" Lua.callfunc l "hello" Lua.callfunc l "hello" ""
I know the Lua bridge is working because the following works:
Lua.callproc l "print" "Hello from Lua"
Any help is appreciated! -deech

That worked. Thank you! -deech On Sat, Oct 23, 2010 at 1:49 PM, Claude Heiland-Allen < claudiusmaximus@goto10.org> wrote:
Hi Aditya,
The problem is not that the file was not loaded, but that in Lua, loading a file only loads it and does not execute it; Lua is a "dynamic" language, by which I mean that definitions are created through execution.
Attached is a simple example, note that there is no proper error checking - you probably want to check the results rather than pattern matching against constants.
Thanks,
Claude
On 23/10/10 03:21, aditya siram wrote:
Hi all, I'm having some issues calling Lua functions from Haskell. I have the following in "Haskell2Lua.lua": function hello () return "hello world" end
And my Haskell file "Haskell2Lua.hs" looks like this: import qualified Scripting.Lua as Lua
main = do
l<- Lua.newstate
Lua.openlibs l
succ<- Lua.loadfile l "/Haskell2Lua.lua"
print succ
Lua.callproc l "hello" ""
Lua.close l
When I compile and run this file I get: 0 Haskell2Lua: user error (attempt to call a nil value)
I have tried some variations on calling the function including: Lua.callproc l "hello" Lua.callfunc l "hello" Lua.callfunc l "hello" ""
I know the Lua bridge is working because the following works:
Lua.callproc l "print" "Hello from Lua"
Any help is appreciated! -deech
-- http://claudiusmaximus.goto10.org
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
aditya siram
-
Claude Heiland-Allen
-
Gracjan Polak