add_constant("this_user", function_object(backtrace()[-2]->fun));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
That will be relative to where you do add_constant, is that really what you want?
You probably want to do something like,
| User calculate_current_user() | { | // really calculate the user from for instance the backtrace | return ...; | } | | ... | add_constant("this_user",calculate_current_user);
/ Mirar
Previous text:
2003-08-29 08:18: Subject: Problems with Backtrace
Pardon my ignorance, but here it goes.
I am at the moment writing a general LPC-type server in Pike, mainly for my own amusement, and have run into a problem. First let me give a rundown. I'm sorry if it's long-winded, I like to put all the information out so I don't confuse with my incorrect jargon and don't miss anything important.
The server sets up all the constants (located in inherited file) binds to a port and listens. Once a connection attempt is found it sends it to a socket class. The socket class then attempts to clone the player object, (compiles the program pointed to by a #define) and calls the logon() in the compiled object.
The server itself, handling connections, cloning of objects, and basically everything works just fine. An LPC-alike clone mud can be built. I have a constant:
add_constant("this_user", function_object(backtrace()[-2]->fun));
Which works wonderfully enough while it is inside the player program.
My problem:
I have a "bin" system for the player commands. It matches the input, searches for an object compiled under that name (i.e. /lib/cmds/who.p when they type who), compiling if not, then calls the do_cmd() function within it. If the this_user() constant is called from within the called command function it returns 0. A backtrace returns an array of 3 Zeroes. The "function_object(backtrace()[-2]->fun)" works fine within it, only the constant has a problem.
Currently I am circumventing this by using a #define for the backtrace, but it is rather annoying and unsightly. I was wondering if there was some other way of doing this, or if I was doing something hideously wrong. At least some way of hitting the backtrace info from within such an above example, I can always set checking to make sure it's hitting the right backtrace entry, just need the info first *grin*.
Kaylus
p.s. Sorry if this was somewhat lengthy, pointless, blather that is hard to read. It's 2am and i've been trying to figure it out for quite some time. Please ignore slight errors in the message!
/ kaylus