From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,72137304956d9360 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-19 14:18:07 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsmi-us.news.garr.it!NewsITBone-GARR!news.mailgate.org!newsfeed.stueberl.de!fu-berlin.de!uni-berlin.de!82-43-33-75.cable.ubr01.croy.blueyonder.co.UK!not-for-mail From: "Nick Roberts" Newsgroups: comp.lang.ada Subject: Re: generic imports? void* -> generics? Date: Fri, 19 Sep 2003 22:18:04 +0100 Message-ID: References: NNTP-Posting-Host: 82-43-33-75.cable.ubr01.croy.blueyonder.co.uk (82.43.33.75) X-Trace: news.uni-berlin.de 1064006286 1489020 82.43.33.75 (16 [25716]) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 Xref: archiver1.google.com comp.lang.ada:42698 Date: 2003-09-19T22:18:04+01:00 List-Id: "chris" wrote in message news:FBIab.3309$DM5.35123@newsfep4-glfd.server.ntli.net... > Should the following C code be mapped to a generic? > > void *lua_touserdata (Lua_State* L, int pos) Not directly. I would suggest that you take the following approach. package Stream_C_Pointers is new Interfaces.C.Pointers( Index => Ada.Streams.Stream_Element_Offset, Element => Ada.Streams.Stream_Element, Element_Array => Ada.Streams.Stream_Element_Array ); subtype Stream_C_Pointer is Stream_C_Pointers.Pointer; use Stream_C_Pointers; function LUA_To_User_Data (State: access LUA_State; Pos: Interfaces.C.int) returns Stream_C_Pointer; pragma Import(C,LUA_To_User_Data,"lua_touserdata"); The general idea is that Ada code is able to read a variable from the memory area returned by this C function, interpreted as a stream array so that the variable's stream-oriented Read procedure or Input function can be used directly. There could well be difficulties associated with writing data using C code and then reading it using (stream-oriented) Ada code. You may well wish to wrap all this up in a package or a generic package, at a higher level of organisation. Hope this helps. I'd be happy to give more detail if you wish. -- Nick Roberts Jabber: debater@charente.de [ICQ: 159718630]