[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Solved: thks - Unable to access table using lua after creation of table in C
- From: "Dr Christopher S Kirk" <drcskirk@...>
- Date: Thu, 12 Mar 2009 13:46:03 +0000
Thank you very much for your observations.
I had in fact tried this solution and still failed.
I reworked a test script and achieved success.
The reason for the failure appears to be that I wrapped the solution
inside another 'C' function which had not been registered in the correct
form for use bu lua. This suggests that scoping is more stringent than
I had thought and propagation of mixed functions across the code is
difficult.
This is embarrassing and I apologise if I wasted time.
The solution will form part of work to handle raw packet analysis. I
will announce progress when further work has been accomplished.
Many thanks
Chris
On Wed, 11 Mar 2009 15:28:06 +0000 (UTC), "Dolphin"
<dhawkins@netstreams.com> said:
> I would suggest looking at http://www.lua.org/pil/24.2.html (The Stack).
> Most
> of the lua C API operates on values on the stack. I use
> http://pgl.yoyo.org/luai/i/_
> as a reference when I need to remember what the functions do. Stack
> programming
> takes a bit of getting used to, and some of the lua C api may do thinks
> you are
> not expecting until you get a bit more comfortable with it.
>
> To create a new global table named "tablename" in C you can do:
>
> lua_newtable(L); //[{}]
> lua_setglobal(L, "tablename"); //
>
> If you want to create the table AND add a c function to it.
>
> lua_newtable(L); //[{}]
> lua_pushcfunction(L, someFunc); //[somefunc, {}]
> lua_setfield(L, -2, "someFuncName");//[{somefuncName=somefunc}]
> lua_setglobal(L, "tablename"); //[]
>
> if you need to access an existing table and add a c function:
> lua_getglobal(L, "tablename"); //[{}]
> lua_pushcfunction(L, someFunc); //[somefunc, {}]
> lua_setfield(L, -2, "someFuncName");//[{somefuncName=somefunc}]
> lua_pop(L, 1); //[]
>
> When I first started writing lua C code it helped me to put in comments
> what the
> stack looks like after every command.
>
>
--
Dr Christopher S Kirk
private email services: http://www.fastmail.fm