lua-users home
lua-l archive

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

Hi Shane,

If that snippet with the call to luaL_dofile is being run every time you call the function from C, then that'll be what's causing the problem, as David described above. It's rerunning the code in that file and clobbering your existing remember table. Without looking at the rest of the code for correctness, you probably want to call luaL_dofile on your script just once, and then just use the mechanism for calling the function when you want to invoke it.


On 8/23/07, Shane Lee <> wrote:
On 8/23/07, Patrick Donnelly <> 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) {

  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.