lua-users home
lua-l archive

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


Well, I see two possibilities. You could either walk the entire global environment to see if you can find the function you are looking for or you can keep a dictionary of (pointer, function name)-pairs manually. Neither of them is full-proof, though.

The problem in general is that there is no such thing as a one-to-one correspondence of functions and names (although references might be a more accurate term). It's possible for a function to have several names, or to have none. Let me change your example a bit to illustrate just one possible problem.

A = {}

function f()
   print('lalala')
end

A.callback = f
f = nil

All I did was add a line at the end, but this makes the task you are trying to complete impossible. The name the function had at the time you assigned that function to A.callback is not a valid name for that function anymore.

As I said, this is just one possible problem. Another one is that a function might have have two different names. Which one do you want?

Under certain circumstances, where these problems would not be an issue for you, you might be able to do what you ask for, but tread with care.

William


Sergey Beloshitsky wrote:

Alex Queiroz wrote:

Hallo,

On 8/14/06, Sergey Beloshitsky <sergey@rostok-games.com.ua> wrote:


I have procedure (in C) which saves my tables, but among numbers and
strings they also have pointers to functions, so i would like to save
function names instead of pointers and then, when loading, swap names
back to pointers(it is quite easy).

can someone help me with this task?


Why don't you use the names of the functions as the table keys?

but how?
for example i have table A, and function f

A = {}
function f()
print("lalala")
end

then i do next
A.callback = f;

so anywhere in my scripts i can do A.callback();
and then i want to save my table A. How can i substitute pointer by function name?