comp.lang.ada
 help / color / mirror / Atom feed
* Please help with my lua binding
@ 2013-01-02 18:46 Patrick
  2013-01-02 19:03 ` Patrick
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Patrick @ 2013-01-02 18:46 UTC (permalink / raw)


Hello Everyone

I am trying to make a binding to Lua. 

Although I had to comment out a couple of functions, I have three compiling spec files for the three lua headers that are needed to form a binding.

I have a great free pascal binding to use as an example

I used fdump-ada-spec-slim and it helped a lot. I was able to sort out most of the types and macros by hand.

In lua, lua_State holds the instance of lua. It is an empty struct in the header and fdump skips it.

I don't really know how to represent this structure in lua.

I tried to define it as:

type lua_State is access lua_State;
pragma Import (C, lua_State, "lua_State");

 but when I call it in this piece of code:

with lauxlib_h ; use lauxlib_h ;
with lualib_h ; use lualib_h ;
with lua_h ; use lua_h ;


procedure test is
result : Integer ;
type L is access lua_State ;


begin

L := luaL_newstate ;
 
end test ;

I get this:
test.adb:27:01: invalid use of subtype mark in expression or call
lua_h.ads:149:26: type "lua_State" cannot be used before end of its declaration
lua_h.ads:150:19: second argument of pragma "import" must be object or subprogram
gnatmake: "test.adb" compilation error

In the pascal biding lua_State is:
Plua_State = Pointer;

They put a P at the start to show it is a pointer.

An example of it's use in C is:
int main(void)
{
    
lua_State *L;
L = luaL_newstate();  /* Create Lua state variable */
luaL_openlibs(L);     /* Load Lua libraries */
continues....

interfaces.C helps me a lot but outside of it I get mixed up working with C. Does anyone have any hints on how I could define lua_State in my spec file?

Thanks for reading.



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

* Re: Please help with my lua binding
  2013-01-02 18:46 Please help with my lua binding Patrick
@ 2013-01-02 19:03 ` Patrick
  2013-01-02 19:31 ` Florian Weimer
  2013-01-02 19:46 ` Florian Weimer
  2 siblings, 0 replies; 13+ messages in thread
From: Patrick @ 2013-01-02 19:03 UTC (permalink / raw)


Sorry that was :
"I don't really know how to represent this structure in Ada.



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

* Re: Please help with my lua binding
  2013-01-02 18:46 Please help with my lua binding Patrick
  2013-01-02 19:03 ` Patrick
@ 2013-01-02 19:31 ` Florian Weimer
  2013-01-02 19:46 ` Florian Weimer
  2 siblings, 0 replies; 13+ messages in thread
From: Florian Weimer @ 2013-01-02 19:31 UTC (permalink / raw)


* > I tried to define it as:
>
> type lua_State is access lua_State;
> pragma Import (C, lua_State, "lua_State");

   type lua_State is private;

And then:

   type lua_State is new System.Address;

It's not 100% correct, but I'm pretty sure it works on all GCC-based
platforms support by GNAT.



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

* Re: Please help with my lua binding
  2013-01-02 18:46 Please help with my lua binding Patrick
  2013-01-02 19:03 ` Patrick
  2013-01-02 19:31 ` Florian Weimer
@ 2013-01-02 19:46 ` Florian Weimer
  2013-01-02 19:55   ` Patrick
  2 siblings, 1 reply; 13+ messages in thread
From: Florian Weimer @ 2013-01-02 19:46 UTC (permalink / raw)


* > I tried to define it as:
>
> type lua_State is access lua_State;
> pragma Import (C, lua_State, "lua_State");

   type lua_State is private;

And then:

   type lua_State is new System.Address;

This actually serves as "lua_State *" on the Ada side.  It's not 100%
correct, but I'm pretty sure it works on all GCC-based platforms
support by GNAT.



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

* Re: Please help with my lua binding
  2013-01-02 19:46 ` Florian Weimer
@ 2013-01-02 19:55   ` Patrick
  2013-01-02 20:08     ` Simon Wright
  2013-01-02 20:08     ` Florian Weimer
  0 siblings, 2 replies; 13+ messages in thread
From: Patrick @ 2013-01-02 19:55 UTC (permalink / raw)


Thanks Florian, your helping me on two lists !

Sorry to be so dense....

In my lua_h.ads file I put this:
type lua_State is private;
type lua_State is new System.Address;

and in the test.adb file I did this:
procedure test is
result : Integer ;
L : lua_State ;

begin

L := luaL_newstate ;
 
end test ;


I got this:
test.adb:13:06: expected private type "lua_State" defined at lua_h.ads:161
test.adb:13:06: found private type "System.Address"
lua_h.ads:161:01: declaration of full view must appear in private part
gnatmake: "test.adb" compilation error


I don't understand the error because I don't understand the difference between access and system.address enough.

I will read more about it tonight.

Thanks again for all your time



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

* Re: Please help with my lua binding
  2013-01-02 19:55   ` Patrick
@ 2013-01-02 20:08     ` Simon Wright
  2013-01-03  5:51       ` Jeffrey Carter
  2013-01-02 20:08     ` Florian Weimer
  1 sibling, 1 reply; 13+ messages in thread
From: Simon Wright @ 2013-01-02 20:08 UTC (permalink / raw)


Patrick <patrick@spellingbeewinnars.org> writes:

> In my lua_h.ads file I put this:
> type lua_State is private;
> type lua_State is new System.Address;
>
> and in the test.adb file I did this:
> procedure test is
> result : Integer ;
> L : lua_State ;
>
> begin
>
> L := luaL_newstate ;
>  
> end test ;
>
>
> I got this:
> test.adb:13:06: expected private type "lua_State" defined at lua_h.ads:161
> test.adb:13:06: found private type "System.Address"

These are because GNAT has been confused by ...

> lua_h.ads:161:01: declaration of full view must appear in private part

So you need to say

with System;
package lua_h is
   ...
   type lua_state is private;
   ...
private                         -- this begins the private part
   ...
   type lua_state is new System.Address;
   ...
end lua_h;



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

* Re: Please help with my lua binding
  2013-01-02 19:55   ` Patrick
  2013-01-02 20:08     ` Simon Wright
@ 2013-01-02 20:08     ` Florian Weimer
  2013-01-02 22:37       ` Patrick
  2013-01-02 23:17       ` Patrick
  1 sibling, 2 replies; 13+ messages in thread
From: Florian Weimer @ 2013-01-02 20:08 UTC (permalink / raw)


> I got this:
> test.adb:13:06: expected private type "lua_State" defined at lua_h.ads:161
> test.adb:13:06: found private type "System.Address"
> lua_h.ads:161:01: declaration of full view must appear in private part
> gnatmake: "test.adb" compilation error

Please post more complete sources.  You need something like this:

with System;

package Lua_H is

   type lua_State is private;

   function luaL_newState return lua_State;

private

   type lua_State is new System.Address;

   pragma Import (C, luaL_newState, "luaL_newState");
end;

with Lua_H;

procedure Test is
   L : Lua_H.lua_State;
begin
   L := Lua_H.luaL_newState;
end Test;

(Later, you should probably drop the prefixes and move the luaL
functions to a separate package.)



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

* Re: Please help with my lua binding
  2013-01-02 20:08     ` Florian Weimer
@ 2013-01-02 22:37       ` Patrick
  2013-01-02 23:17       ` Patrick
  1 sibling, 0 replies; 13+ messages in thread
From: Patrick @ 2013-01-02 22:37 UTC (permalink / raw)


I just deleted my last post, that was way too much code to post.....

Here is what was posted otherwise...

Thanks Simon, Thanks Florian 

I have to work right now. I'm in trouble with my taxes ! but I will keeping trying later tonight. 

I am not asking for anyone to write this for me but if you want to see what I am up to, all the gory details are at the end. 

I will try to do this on my own too, thanks for all your help! 



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

* Re: Please help with my lua binding
  2013-01-02 20:08     ` Florian Weimer
  2013-01-02 22:37       ` Patrick
@ 2013-01-02 23:17       ` Patrick
  2013-01-03  7:08         ` Patrick
  1 sibling, 1 reply; 13+ messages in thread
From: Patrick @ 2013-01-02 23:17 UTC (permalink / raw)


Thanks again Simon and Florian

My lua state is fine now, I have more problems but I will work through them. I hope this works out !

Thanks again



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

* Re: Please help with my lua binding
  2013-01-02 20:08     ` Simon Wright
@ 2013-01-03  5:51       ` Jeffrey Carter
  2013-01-03  9:03         ` Simon Wright
  0 siblings, 1 reply; 13+ messages in thread
From: Jeffrey Carter @ 2013-01-03  5:51 UTC (permalink / raw)



On 01/02/2013 01:08 PM, Simon Wright wrote:
 >
 > These are because GNAT has been confused by ...
 >
 >> lua_h.ads:161:01: declaration of full view must appear in private part
 >
 > So you need to say
 >
 > with System;
 > package lua_h is
 >     ...
 >     type lua_state is private;
 >     ...
 > private                         -- this begins the private part
 >     ...
 >     type lua_state is new System.Address;
 >     ...
 > end lua_h;

This is such basic and essential Ada that if the OP doesn't understand it, he 
shouldn't be doing anything advanced, such as writing a binding, until he does.

-- 
Jeff Carter
"My brain hurts!"
Monty Python's Flying Circus
21



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

* Re: Please help with my lua binding
  2013-01-02 23:17       ` Patrick
@ 2013-01-03  7:08         ` Patrick
  0 siblings, 0 replies; 13+ messages in thread
From: Patrick @ 2013-01-03  7:08 UTC (permalink / raw)


I had originally looked for Ada bindings here:

http://lua-users.org/wiki/BindingCodeToLua

Both links were dead. I had downloaded the second link's code last year though but it was very hard for me to understand the build system and I decided to start from scratch.

I found the project reworked with a simple makefile and two gpr files on github. There are two authors, one is here:
https://github.com/Lucretia/coreland-lua-ada

I had a bit of trouble building it but it appears to be a gnat issue.

putting these commands in a shell script helped:
make
make tests
LIBRARY_PATH=$LIBRARY_PATH:/usr/lib/x86_64-linux-gnu /pat/gnat/bin/gnatmake -Plua_ada_tests
(you would of course have to edit this last line)

The library path does not seem to be found by default and must be specified.

This project does not appear complete but it is miles ahead of where I was a few hours ago. I am going to study it and put my project on hold.

Thanks to Florian and Simon again. I suppose my efforts are a failure at this point but I have learned quite a bit. Ada is a wonderful language but I have not been actually writing enough to organize all the pieces I have read. Trying out projects is a great way to learn and I learned several things today.



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

* Re: Please help with my lua binding
  2013-01-03  5:51       ` Jeffrey Carter
@ 2013-01-03  9:03         ` Simon Wright
  2013-01-03  9:45           ` Florian Weimer
  0 siblings, 1 reply; 13+ messages in thread
From: Simon Wright @ 2013-01-03  9:03 UTC (permalink / raw)


Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> writes:

> On 01/02/2013 01:08 PM, Simon Wright wrote:
>>
>> These are because GNAT has been confused by ...
>>
>>> lua_h.ads:161:01: declaration of full view must appear in private part
>>
>> So you need to say
>>
>> with System;
>> package lua_h is
>>     ...
>>     type lua_state is private;
>>     ...
>> private                         -- this begins the private part
>>     ...
>>     type lua_state is new System.Address;
>>     ...
>> end lua_h;
>
> This is such basic and essential Ada that if the OP doesn't understand
> it, he shouldn't be doing anything advanced, such as writing a
> binding, until he does.

Well, the compiler messages were quite confusing.



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

* Re: Please help with my lua binding
  2013-01-03  9:03         ` Simon Wright
@ 2013-01-03  9:45           ` Florian Weimer
  0 siblings, 0 replies; 13+ messages in thread
From: Florian Weimer @ 2013-01-03  9:45 UTC (permalink / raw)


* Simon Wright:

> Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> writes:
>> This is such basic and essential Ada that if the OP doesn't understand
>> it, he shouldn't be doing anything advanced, such as writing a
>> binding, until he does.
>
> Well, the compiler messages were quite confusing.

Indeed, errors in the package spec reported *after* errors in its body
led me astray a couple of times as well.



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

end of thread, other threads:[~2013-01-03  9:45 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-02 18:46 Please help with my lua binding Patrick
2013-01-02 19:03 ` Patrick
2013-01-02 19:31 ` Florian Weimer
2013-01-02 19:46 ` Florian Weimer
2013-01-02 19:55   ` Patrick
2013-01-02 20:08     ` Simon Wright
2013-01-03  5:51       ` Jeffrey Carter
2013-01-03  9:03         ` Simon Wright
2013-01-03  9:45           ` Florian Weimer
2013-01-02 20:08     ` Florian Weimer
2013-01-02 22:37       ` Patrick
2013-01-02 23:17       ` Patrick
2013-01-03  7:08         ` Patrick

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