[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: need help understanding C API
- From: Patrick <patrick@...>
- Date: Tue, 01 Jan 2013 19:52:59 -0500
Hello
I am trying to write a binding for Lua and I have hit a snag because I
don't really understand the plain C API well enough.
Could someone please tell me if this is wrong..
If we do this:
int * foo
we have created a pointer that can accept an int's value at a specific
memory location.
If we do this:
lua_State * foo
We have "prepared" a memory location for all kinds if types ints, chars,
function pointers and so on that lua will need and when we do this:
foo = luaL_newstate()
We are propagating that memory location with values and that memory
location is now a lua instance.
Did I get this right?
So this must be silly but I can't figure it out. I know this isn't good
programming practice but if I do this:
lua_State *L;
L = luaL_newstate();
int main(void)
{ code continues.....
I get these errors:
hello.c:17:1: warning: data definition has no type or storage class
[enabled by default]
hello.c:17:1: error: conflicting types for ‘L’
hello.c:16:12: note: previous declaration of ‘L’ was here
hello.c:17:5: warning: initialization makes integer from pointer without
a cast [enabled by default]
hello.c:17:1: error: initializer element is not constant
If the space is allocated and propagated in global space would it not
just be available later inside a function scope?
I have a binding generator that will help but it won't work inside
function scope. I am trying to run it on globals and I am trying to
learn more about the C API as I go along.
Thanks for reading
Happy birthday to Michal Kottman, my birthday is 2 hours away !
-Patrick