comp.lang.ada
 help / color / mirror / Atom feed
* Questions on using prgma Import (C, foo)
@ 2008-02-25 19:22 pfpearson.net
  2008-02-25 19:28 ` Pascal Obry
  2008-02-26 10:51 ` Jean-Pierre Rosen
  0 siblings, 2 replies; 9+ messages in thread
From: pfpearson.net @ 2008-02-25 19:22 UTC (permalink / raw)


I'm writing some Ada bindings for lua ( http://www.lua.org/ ), a very
small and fast interpreter with a clean C API.  While I've been
developing Ada for years, this is my first real foray into importing C
libraries (I've done the occasional import of memcpy() or such).

My question is how to handle C functions that return "char *".  The
Lua function is question is:
     const char *lua_tolstring (lua_State *L, int index, size_t *len);

At first I just wrote this as:
  function lua_tolstring (L: lua_State_ptr; index: inteter; len :
size_t_ptr) return Interfaces.C.Char_array;

However, it only took me a minute to realize that this won't work.
I see two options:
1. function lua_tolstring (...) return System.Adddress;
2. use the types declared in Interfaces.C.Strings.

Has anyone else been down this path?  If so, can you share your
experiences?

I've read the AARM, and done some Googling, and looked through the
sources in Gnat.  If you want me to RTFM, then please point me to the
manual, and I will gladly read it!

thanks!



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Questions on using prgma Import (C, foo)
  2008-02-25 19:22 Questions on using prgma Import (C, foo) pfpearson.net
@ 2008-02-25 19:28 ` Pascal Obry
  2008-02-25 19:48   ` pfpearson.net
  2008-02-26 10:51 ` Jean-Pierre Rosen
  1 sibling, 1 reply; 9+ messages in thread
From: Pascal Obry @ 2008-02-25 19:28 UTC (permalink / raw)
  To: pfpearson.net

pfpearson.net@gmail.com a �crit :
> However, it only took me a minute to realize that this won't work.
> I see two options:
> 1. function lua_tolstring (...) return System.Adddress;
> 2. use the types declared in Interfaces.C.Strings.

2 is better I think:

    function lua_tolstring
     (L     : lua_State_ptr;
      index : inteter;
      len   : size_t_ptr) return Interfaces.C.Strings.chars_ptr;

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Questions on using prgma Import (C, foo)
  2008-02-25 19:28 ` Pascal Obry
@ 2008-02-25 19:48   ` pfpearson.net
  2008-02-26 12:15     ` Jeffrey Creem
  2008-02-26 13:50     ` Stephen Leake
  0 siblings, 2 replies; 9+ messages in thread
From: pfpearson.net @ 2008-02-25 19:48 UTC (permalink / raw)


On Feb 25, 1:28 pm, Pascal Obry <pas...@obry.net> wrote:
> pfpearson....@gmail.com a écrit :
>
> > However, it only took me a minute to realize that this won't work.
> > I see two options:
> > 1. function lua_tolstring (...) return System.Adddress;
> > 2. use the types declared in Interfaces.C.Strings.
>
> 2 is better I think:
>
>     function lua_tolstring
>      (L     : lua_State_ptr;
>       index : inteter;
>       len   : size_t_ptr) return Interfaces.C.Strings.chars_ptr;
>
> Pascal.

That's what I suspected.  Thanks.

Once I've gotten this done, is anyone interested in using this?  Lua
really is a neat embedded langauge.  I hope to use it at work to
handle reading in init data, and possibly to script some of the
program's behavior.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Questions on using prgma Import (C, foo)
  2008-02-25 19:22 Questions on using prgma Import (C, foo) pfpearson.net
  2008-02-25 19:28 ` Pascal Obry
@ 2008-02-26 10:51 ` Jean-Pierre Rosen
  2008-02-26 20:01   ` pfpearson.net
  1 sibling, 1 reply; 9+ messages in thread
From: Jean-Pierre Rosen @ 2008-02-26 10:51 UTC (permalink / raw)


pfpearson.net@gmail.com a �crit :
> I'm writing some Ada bindings for lua ( http://www.lua.org/ ), a very
> small and fast interpreter with a clean C API.  
There used to be an Ada binding to Lua at 
http://www.cyberdanx.co.uk/ada95/lua.html

The link seems broken now, but the marvelous time machine at 
http://web.archive.org has saved a copy as:

http://web.archive.org/web/20060225040957/http://www.cyberdanx.co.uk/ada95/lua-binding-0.10.tar.bz2

That would certainly be a good starting point (maybe an endpoint for you 
if the binding is complete enough - I never tried it personally)

-- 
---------------------------------------------------------
            J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Questions on using prgma Import (C, foo)
  2008-02-25 19:48   ` pfpearson.net
@ 2008-02-26 12:15     ` Jeffrey Creem
  2008-02-26 13:50     ` Stephen Leake
  1 sibling, 0 replies; 9+ messages in thread
From: Jeffrey Creem @ 2008-02-26 12:15 UTC (permalink / raw)


pfpearson.net@gmail.com wrote:
> On Feb 25, 1:28 pm, Pascal Obry <pas...@obry.net> wrote:
>> pfpearson....@gmail.com a �crit :
>>
>>> However, it only took me a minute to realize that this won't work.
>>> I see two options:
>>> 1. function lua_tolstring (...) return System.Adddress;
>>> 2. use the types declared in Interfaces.C.Strings.
>> 2 is better I think:
>>
>>     function lua_tolstring
>>      (L     : lua_State_ptr;
>>       index : inteter;
>>       len   : size_t_ptr) return Interfaces.C.Strings.chars_ptr;
>>
>> Pascal.
> 
> That's what I suspected.  Thanks.
> 
> Once I've gotten this done, is anyone interested in using this?  Lua
> really is a neat embedded langauge.  I hope to use it at work to
> handle reading in init data, and possibly to script some of the
> program's behavior.

It certainly is the sort of thing that can be generally useful even if 
no one has a specific need for it now. I'd suggest managing it on one of 
the big open source project websites so other can see it and use it 
should you ever abandon the project years from now.

My projects are all on sourceforge. There are those that (probably 
justifiably) would rather host on a other sites (like gna.org) which is 
also fine. It is nice however to pick someplace that will outlive  you 
and has an abandon project takeover capability.

Also consider your goals for licensing when you release the project but 
do pick a license.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Questions on using prgma Import (C, foo)
  2008-02-25 19:48   ` pfpearson.net
  2008-02-26 12:15     ` Jeffrey Creem
@ 2008-02-26 13:50     ` Stephen Leake
  2008-02-26 19:59       ` pfpearson.net
  1 sibling, 1 reply; 9+ messages in thread
From: Stephen Leake @ 2008-02-26 13:50 UTC (permalink / raw)


pfpearson.net@gmail.com writes:

> On Feb 25, 1:28 pm, Pascal Obry <pas...@obry.net> wrote:
>> pfpearson....@gmail.com a �crit :
>>
>> > However, it only took me a minute to realize that this won't work.
>> > I see two options:
>> > 1. function lua_tolstring (...) return System.Adddress;
>> > 2. use the types declared in Interfaces.C.Strings.
>>
>> 2 is better I think:
>>
>>     function lua_tolstring
>>      (L     : lua_State_ptr;
>>       index : inteter;
>>       len   : size_t_ptr) return Interfaces.C.Strings.chars_ptr;
>>
>> Pascal.
>
> That's what I suspected.  Thanks.

You should also consider providing a slightly thicker wrapper that
does the conversion from Interfaces.C.Strings.chars_ptr to
Standard.String; that will make this easier to use with plain Ada
programs.

> Once I've gotten this done, is anyone interested in using this?  Lua
> really is a neat embedded langauge.  I hope to use it at work to
> handle reading in init data, and possibly to script some of the
> program's behavior.

Lua is used by monotone (http://monotone.ca), a distributed
configuration management system, that I'm starting to use. So I'm also
starting to use Lua.

It is a nice languaged, well designed for embedding in larger
projects.

Lua has a website: http://www.lua.org/

I'm not clear on how it manages dynamically allocated memory; that
would be a concern for some embedded systems.

I'm currently using OpenToken to build my own language for controlling
my simulator. That language has no control structures or subroutines.
I might consider switching to Lua to gain those things.

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Questions on using prgma Import (C, foo)
  2008-02-26 13:50     ` Stephen Leake
@ 2008-02-26 19:59       ` pfpearson.net
  0 siblings, 0 replies; 9+ messages in thread
From: pfpearson.net @ 2008-02-26 19:59 UTC (permalink / raw)


On Feb 26, 7:50 am, Stephen Leake <stephen_le...@stephe-leake.org>
wrote:
> You should also consider providing a slightly thicker wrapper that
> does the conversion from Interfaces.C.Strings.chars_ptr to
> Standard.String; that will make this easier to use with plain Ada
> programs.

I plan on doing that, once I have the thin wrapper done.  A reason for
the thin wrapper is to retain speed - one of the benefits of lua.

> Lua has a website:http://www.lua.org/

Gee, I wish I'd said that :-)

> I'm not clear on how it manages dynamically allocated memory; that
> would be a concern for some embedded systems.

That's a good question, to which I may try to find an answer.  I don't
develop for embedded systems (I hope I didn't misuse the phrase
"embedded language" - I meant a language "embedded" within my
program), so I hadn't really thought about it much.

> I'm currently using OpenToken to build my own language for controlling
> my simulator. That language has no control structures or subroutines.
> I might consider switching to Lua to gain those things.

In general, I prefer to reuse languages -  *everyone* writes their
own, including where I work.  It's pretty poor (effective, but limited
and I suspect that it's slower than lua), which is why I want to
propose the use of lua.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Questions on using prgma Import (C, foo)
  2008-02-26 10:51 ` Jean-Pierre Rosen
@ 2008-02-26 20:01   ` pfpearson.net
  2008-03-10 20:29     ` Alexey Veselovsky
  0 siblings, 1 reply; 9+ messages in thread
From: pfpearson.net @ 2008-02-26 20:01 UTC (permalink / raw)


On Feb 26, 4:51 am, Jean-Pierre Rosen <ro...@adalog.fr> wrote:
> pfpearson....@gmail.com a écrit :> I'm writing some Ada bindings for lua (http://www.lua.org/), a very
> > small and fast interpreter with a clean C API.
>
> There used to be an Ada binding to Lua athttp://www.cyberdanx.co.uk/ada95/lua.html
>
> The link seems broken now, but the marvelous time machine athttp://web.archive.orghas saved a copy as:
>
> http://web.archive.org/web/20060225040957/http://www.cyberdanx.co.uk/...
>
> That would certainly be a good starting point (maybe an endpoint for you
> if the binding is complete enough - I never tried it personally)

Thanks!  I'd only found the broken link, and hadn't used the time
machine.  I'll look at that.  I think lua's been updated a bit over
the last couple of years, so that may actually *be* a starting point.
Hopefully, it'll be okay for me to pick up where that author left
off.   If I can, I'll try to get a project set up at SourceForge, as
has been suggested.  That way, it should stay around when I stop
maintaining it (which is very likely).



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Questions on using prgma Import (C, foo)
  2008-02-26 20:01   ` pfpearson.net
@ 2008-03-10 20:29     ` Alexey Veselovsky
  0 siblings, 0 replies; 9+ messages in thread
From: Alexey Veselovsky @ 2008-03-10 20:29 UTC (permalink / raw)


> Thanks!  I'd only found the broken link, and hadn't used the time
> machine.  I'll look at that.  I think lua's been updated a bit over
> the last couple of years, so that may actually *be* a starting point.
> Hopefully, it'll be okay for me to pick up where that author left
> off.   If I can, I'll try to get a project set up at SourceForge, as
> has been suggested.  That way, it should stay around when I stop
> maintaining it (which is very likely).

I'm interested in this project.
May be it will be easier to create project on google.code:
http://code.google.com/hosting/

I use it for my opensource projects.




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-03-10 20:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-25 19:22 Questions on using prgma Import (C, foo) pfpearson.net
2008-02-25 19:28 ` Pascal Obry
2008-02-25 19:48   ` pfpearson.net
2008-02-26 12:15     ` Jeffrey Creem
2008-02-26 13:50     ` Stephen Leake
2008-02-26 19:59       ` pfpearson.net
2008-02-26 10:51 ` Jean-Pierre Rosen
2008-02-26 20:01   ` pfpearson.net
2008-03-10 20:29     ` Alexey Veselovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox