lua-users home
lua-l archive

Re: [NOOB] "remember" function

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 8/23/07, Patrick Donnelly <batrick.donnelly@gmail.com> wrote:
> Sorry if that seems like nit picking but I found what you did incredibly odd.
Actually, that was like the tenth re-write I had to make before I got
the stupid thing working at all.
>
> Anyways, seeing your C code is necessary for us to help you I think.
> Just be sure to trim it to show only relevant portions.
Okay, but remember, you asked for it...
Here is the retrieval function...
--------------------C code snip--------------------
char *LUA_STR(lua_State *L) {
 (void)L;
 if (!L) {
 warn("%s: Called by NULL Lua State!", __func__);
 return (NULL);
 }
 char *ret = (char *)lua_tostring(L, -1);
 return (ret);
}
-------------------C code snip---------------------
And here is a snippet from the function that passes the data and calls
the retrieval function:
--------------------C code snip--------------------
 if (luaL_dofile(L, fl) != 0) {
 warn("%s: Parsing Error for file '%s'", __func__, fl);
 return (NULL);
 }
 lua_getglobal(L, fun);
 if (Exists(a1)) { lua_pushstring(L, a1); }
 if (Exists(a2)) { lua_pushstring(L, a2); }
 if (Exists(a3)) { lua_pushstring(L, a3); }
 if (Exists(a4)) { lua_pushstring(L, a4); }
 /* call the function with 2 arguments, return 1 result */
 lua_call(L, n, 1);
 ret = LUA_STR(L);
 lua_pop(L, 1);
 return (ret);
-----------------------C code snip---------------------
I feel that I should also mention that pretty much everything else I
have tried works fine. I am able to call lua functions and parse the
results in the C ap with no problems so far.
-Shane

AltStyle によって変換されたページ (->オリジナル) /