comp.lang.ada
 help / color / mirror / Atom feed
* C binding issue
@ 2003-05-10 20:30 kat-Zygfryd
  2003-05-10 22:46 ` David Holm
  2003-05-11 22:40 ` Antonio Vargas
  0 siblings, 2 replies; 9+ messages in thread
From: kat-Zygfryd @ 2003-05-10 20:30 UTC (permalink / raw)


I want to write a binding for Lua 5.0
but I encountered a problem:

in lua.h we have this definition:

typedef const char * (*lua_Chunkreader) (lua_State *L, void *ud, size_t
*sz);

question:
how do I define such a callback in Ada, so that I could set
the value of *sz from within it.

Zygfryd





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

* Re: C binding issue
  2003-05-10 20:30 C binding issue kat-Zygfryd
@ 2003-05-10 22:46 ` David Holm
  2003-05-10 23:09   ` kat-Zygfryd
  2003-05-11 15:02   ` Sergey Koshcheyev
  2003-05-11 22:40 ` Antonio Vargas
  1 sibling, 2 replies; 9+ messages in thread
From: David Holm @ 2003-05-10 22:46 UTC (permalink / raw)


Something like this if I'm not mistaken (been a while since I used callbacks in Ada):

type size_t_ptr is access all Interfaces.C.size_t;
type Lua_Chunkreader_Proc is access function
   (L : Lua_State_Type; Ptr : System.Address; Sz : size_t_ptr) return
   Interfaces.C.Strings.chars_ptr;


//David Holm

On Sat, 10 May 2003 22:30:40 +0200
"kat-Zygfryd" <6667@wp.pl> wrote:

> I want to write a binding for Lua 5.0
> but I encountered a problem:
> 
> in lua.h we have this definition:
> 
> typedef const char * (*lua_Chunkreader) (lua_State *L, void *ud, size_t
> *sz);
> 
> question:
> how do I define such a callback in Ada, so that I could set
> the value of *sz from within it.
> 
> Zygfryd
> 
> 



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

* Re: C binding issue
  2003-05-10 22:46 ` David Holm
@ 2003-05-10 23:09   ` kat-Zygfryd
  2003-05-11  2:12     ` David C. Hoos
  2003-05-11 15:02   ` Sergey Koshcheyev
  1 sibling, 1 reply; 9+ messages in thread
From: kat-Zygfryd @ 2003-05-10 23:09 UTC (permalink / raw)


Thanks, I just thought that access types and C pointers
are incompatible.

Zygfryd





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

* Re: C binding issue
  2003-05-10 23:09   ` kat-Zygfryd
@ 2003-05-11  2:12     ` David C. Hoos
  2003-05-11  2:44       ` Jeffrey Carter
  0 siblings, 1 reply; 9+ messages in thread
From: David C. Hoos @ 2003-05-11  2:12 UTC (permalink / raw)



"kat-Zygfryd" <6667@wp.pl> wrote in message
news:b9k0rv$bls$1@news.onet.pl...
> Thanks, I just thought that access types and C pointers
> are incompatible.

Questions of this type are answered in the Ada Reference manual.

This particular case is covered in B.3 (68), viz.:

An Ada access T parameter, or an Ada out or in out parameter of an
elementary type T, is passed as a t* argument to a C function, where t is
the C type corresponding to the Ada type T. In the case of an elementary out
or in out parameter, a pointer to a temporary copy is used to preserve
by-copy semantics.
>
> Zygfryd
>
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>
>





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

* Re: C binding issue
  2003-05-11  2:12     ` David C. Hoos
@ 2003-05-11  2:44       ` Jeffrey Carter
  0 siblings, 0 replies; 9+ messages in thread
From: Jeffrey Carter @ 2003-05-11  2:44 UTC (permalink / raw)


David C. Hoos wrote:
 > "kat-Zygfryd" <6667@wp.pl> wrote in message
 > news:b9k0rv$bls$1@news.onet.pl...
 >
 >> Thanks, I just thought that access types and C pointers are
 >> incompatible.
 >
 > Questions of this type are answered in the Ada Reference manual.
 >
 > This particular case is covered in B.3 (68), viz.:
 >
 > An Ada access T parameter, or an Ada out or in out parameter of an
 > elementary type T, is passed as a t* argument to a C function, where
 > t is the C type corresponding to the Ada type T. In the case of an
 > elementary out or in out parameter, a pointer to a temporary copy is
 > used to preserve by-copy semantics.

This refers to access parameters; the example used a named access type.
These can be made C-compatible by applying pragma Convention to them:

type Void_Ptr is access all Integer;
pragma Convention (C, Void_Ptr);

-- 
Jeff Carter
"Beyond 100,000 lines of code you
should probably be coding in Ada."
P. J. Plauger




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

* Re: C binding issue
  2003-05-10 22:46 ` David Holm
  2003-05-10 23:09   ` kat-Zygfryd
@ 2003-05-11 15:02   ` Sergey Koshcheyev
  2003-05-11 16:27     ` kat-Zygfryd
  2003-05-11 19:01     ` David C. Hoos
  1 sibling, 2 replies; 9+ messages in thread
From: Sergey Koshcheyev @ 2003-05-11 15:02 UTC (permalink / raw)



"David Holm" <david@realityrift.com> wrote in message
news:20030511004621.63e7fbd9.david@realityrift.com...
> Something like this if I'm not mistaken (been a while since I used
callbacks in Ada):
>
> type size_t_ptr is access all Interfaces.C.size_t;
> type Lua_Chunkreader_Proc is access function
>    (L : Lua_State_Type; Ptr : System.Address; Sz : size_t_ptr) return
>    Interfaces.C.Strings.chars_ptr;
>
>
> //David Holm

I think it is possible to just use an out parameter of type size_t, instead
of complicating matters with pointers. Or is there some subtle problem with
this approach?

Sergey.





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

* Re: C binding issue
  2003-05-11 15:02   ` Sergey Koshcheyev
@ 2003-05-11 16:27     ` kat-Zygfryd
  2003-05-11 19:01     ` David C. Hoos
  1 sibling, 0 replies; 9+ messages in thread
From: kat-Zygfryd @ 2003-05-11 16:27 UTC (permalink / raw)


"Sergey Koshcheyev" <serko84@hotmail.com> wrote in message
news:b9lolp$1mnf$1@ns.felk.cvut.cz...
> I think it is possible to just use an out parameter of type size_t,
instead
> of complicating matters with pointers. Or is there some subtle problem
with
> this approach?
>
> Sergey.

It's a function not a procedure.

Zygfryd
>





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

* Re: C binding issue
  2003-05-11 15:02   ` Sergey Koshcheyev
  2003-05-11 16:27     ` kat-Zygfryd
@ 2003-05-11 19:01     ` David C. Hoos
  1 sibling, 0 replies; 9+ messages in thread
From: David C. Hoos @ 2003-05-11 19:01 UTC (permalink / raw)



"Sergey Koshcheyev" <serko84@hotmail.com> wrote in message
news:b9lolp$1mnf$1@ns.felk.cvut.cz...
>
> "David Holm" <david@realityrift.com> wrote in message
> news:20030511004621.63e7fbd9.david@realityrift.com...
> > Something like this if I'm not mistaken (been a while since I used
> callbacks in Ada):
> >
> > type size_t_ptr is access all Interfaces.C.size_t;
> > type Lua_Chunkreader_Proc is access function
> >    (L : Lua_State_Type; Ptr : System.Address; Sz : size_t_ptr) return
> >    Interfaces.C.Strings.chars_ptr;
> >
> >
> > //David Holm
>
> I think it is possible to just use an out parameter of type size_t,
instead
> of complicating matters with pointers. Or is there some subtle problem
with
> this approach?
Out mode parameters are not allowed for functions.
>
> Sergey.
>
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>
>





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

* Re: C binding issue
  2003-05-10 20:30 C binding issue kat-Zygfryd
  2003-05-10 22:46 ` David Holm
@ 2003-05-11 22:40 ` Antonio Vargas
  1 sibling, 0 replies; 9+ messages in thread
From: Antonio Vargas @ 2003-05-11 22:40 UTC (permalink / raw)


Hi

I was thinking in a similar project. Do you intend to make the binding
public under GNU?

"kat-Zygfryd" <6667@wp.pl> wrote in message news:<b9jni3$mh0$1@news.onet.pl>...
> I want to write a binding for Lua 5.0
> ...
> Zygfryd

Antonio Vargas
Barcelos - Portugal



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

end of thread, other threads:[~2003-05-11 22:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-10 20:30 C binding issue kat-Zygfryd
2003-05-10 22:46 ` David Holm
2003-05-10 23:09   ` kat-Zygfryd
2003-05-11  2:12     ` David C. Hoos
2003-05-11  2:44       ` Jeffrey Carter
2003-05-11 15:02   ` Sergey Koshcheyev
2003-05-11 16:27     ` kat-Zygfryd
2003-05-11 19:01     ` David C. Hoos
2003-05-11 22:40 ` Antonio Vargas

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