plua2.0b7 loading C libraries problem

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

plua2.0b7 loading C libraries problem

bugmenot4711
hi,

like you might have read in my last post im trying to write a
Plua extension in C for a kind of extended socket support.

I have currently installed:
>Plua 2.0b7 (with the delivered libkit)
>prc-tools
>Palm SDK 5.0r3
additionally I have downloaded dbhack and dlk.

"make" works on all sources (dbhack creates the warning: global data
ignored).
So I've installed the prc files on my palm, opened the Plua2 shell
and typed:

loadlib("dbhack","dbhack")
print(dbhack)

But dbhack is nil....
I've tried the same with the delivered TestLib.c

loadlib("test","test")
print("test")

The same result... also with loadlib("testlib","test")
-> 'cause I've no idea how this extension stuff really works in Plua

At the moment I'm completely frustrated because nothing I've tried
worked. I also wrote my own extension and was able to load it once,
but I have no idea how. The loaded lib didn't really work, but I've
seen a function name I've defined.
Do you have any Idea what I did wrong?

Reply | Threaded
Open this post in threaded view
|

RE: plua2.0b7 loading C libraries problem

Blake Winton-3
> loadlib("dbhack","dbhack")
> print(dbhack)

This should probably be:
libNo = loadlib("dbhack","dbhack")
and then I'ld be interested to see what the result of libNo is.
(I'm guessing 0, but you never know.)

Or perhaps:
lib,err = loadlib( "dbhack" )

(Wow, it looks like it was me who suggested that second one.
 Weird.)

> Do you have any Idea what I did wrong?

Not really.  Can you put your source code somewhere on the web
so that I can take a look at it to see if anything jumps out
at me?

Later,
Blake.
Reply | Threaded
Open this post in threaded view
|

RE: plua2.0b7 loading C libraries problem

Blake Winton-3
In reply to this post by bugmenot4711
Oh, one more thing, from Marcio, at
http://tech.groups.yahoo.com/group/plua/message/3113 
------------------------
> loadlib("extname", "extname")

That is the correct syntax. The second parameter is supposed to be a
function name. In standard Lua, if dynamic library loading is
supported the OS will open the library, search for a function named
"extname" and returns a pointer to it. Then loadlib makes a closure
out of this function and returns it to the caller. In PalmOS however,
there is no OS funcion that works like this. So the library developer
will have to return a function pointer based on the function name
received as parameter to the PluaLibInit function (part of the libkit
API).
------------------------

So, uh, see if that helps.

Later,
Blake.
Reply | Threaded
Open this post in threaded view
|

Re: plua2.0b7 loading C libraries problem

bugmenot4711
Thank you,

I found the problem already:

x = loadlib("LIBNAME AS DEFINED BY SYSLIB", "NAME AS DEFINED BY
luaL_openlib 2nd arg")
-- x is a function (but only at the first call of loadlib)
x()
-- now the variable "NAME AS DEFINED BY luaL_openlib 2nd arg" is set
to the module table, which contains the defined functions.

I'm now trying to find NetLib in C (with SysLibFind) but the palm
performs a hard reset everytime I call it.
Maybe I'll get it working, I'll post the library then.

Reply | Threaded
Open this post in threaded view
|

RE: Re: plua2.0b7 loading C libraries problem

Blake Winton-3
> I'm now trying to find NetLib in C (with SysLibFind) but the
> palm performs a hard reset everytime I call it.
> Maybe I'll get it working, I'll post the library then.

What's your code look like for that?  (Debugging those sorts
of errors is my day job.  Plua's more a hobby.)

I found some sample code at
http://www.codeproject.com/ce/socket_netlib.asp

Later,
Blake.
Reply | Threaded
Open this post in threaded view
|

Re: plua2.0b7 loading C libraries problem

migueletto
In reply to this post by bugmenot4711
Hi,

--- In [hidden email], "bugmenot4711" <bugmenot4711@...> wrote:

> x = loadlib("LIBNAME AS DEFINED BY SYSLIB", "NAME AS DEFINED BY
> luaL_openlib 2nd arg")
> -- x is a function (but only at the first call of loadlib)
> x()
> -- now the variable "NAME AS DEFINED BY luaL_openlib 2nd arg" is set
> to the module table, which contains the defined functions.
>
A small correction: the second argument to loadlib is a function name.
The library function PluaLibInit must return a C function that mathes
this name.  Actually, you can ignore this parameter and return any
function you like, but it is present because Lua defines it.

Regards,
Marcio.