[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [NOOB] "remember" function
- From: "Shane Lee" <shaneplee@...>
- Date: Thu, 23 Aug 2007 14:06:57 -0500
Warning: What follows is a 'noob' question; Proceed with caution!
Okay, I have tried to find the solution to this on my own, but it is
apparently such an easy-to-fix problem that no one has bothered to
write the list about it or put it in the book, unless of course I am
unable to wrap my head around the proper language to describe my
problem in the various search utilities at my disposal:
I have this function in a lua file:
-------------------------code-----------------
remember = {}
function check_memory(who)
local i = 0
local k = 0
if not who then return (nil) end
if (remember[who]) then
k = 0
return("I remember you, " .. who .. "!")
end
if k == 0 then
remember[who] = 1
return ("I am trying to remember you, " .. who .. "!")
end
end
-------------------------code--------------------
And when I do this:
-------------------------code--------------------
local s = nil
s = check_memory("shane")
if not (s) then print ("(nil)") else print (s) end
s = check_memory("shane")
if not (s) then print ("(nil)") else print (s) end
s = check_memory("shane")
if not (s) then print ("(nil)") else print (s) end
-------------------------code------------------
The result is as expected:
-------------------------code------------------
I am trying to remember you, shane!
I remember you, shane!
I remember you, shane!
-------------------------code------------------
Now then, here's the problem; Whenever I attempt to duplicate the
above result using a C call, it constantly "forgets" the last table
entry and no matter how many times I make the call, it returns:
I am trying to remember you, shane!
Because of the complexity of the calling C code, I hesitate to send
that to the list, even under the 'noob' tag, however I can provide
this as well. I am assuming that this has to do with the GC cleaning
up behind me, but I need a way to store a large number of 'names' in
the table along with other possible entries that will not be
"forgotten" each time that the API makes a call.
Now, how's that for an unlurk? Just wait until I get warmed up!
-Shane