gotcha, thanks. So I could just use a dictionary, with the hook name and a list, the list would get appended to to hold the functions?
Thanks, Tyler Littlefield Web: tysdomain.com email: tyler@xxxxxxxxxxxxx My programs don't have bugs, they're called randomly added features.----- Original Message ----- From: "Doug Lee" <dgl@xxxxxxxx>
To: <program-l@xxxxxxxxxxxxx> Sent: Sunday, March 29, 2009 12:07 PM Subject: [program-l] Re: quick python question
Functions are first-class citizens in Python: If you have def f(...), you can say things like myfunc = f, and myarray[2] = f, and myfunc(f). Put another way, if f() calls function f, then f by itself is like a function pointer to f's code. On Sun, Mar 29, 2009 at 11:58:05AM -0600, Tyler Littlefield wrote:hello, I believe I got it working; I just wrote get/set methods for the variables, wihch I can eval. This allows me to control what gets changed via eval, as well. I have one more question; is there a way to do something like an array of function pointers in c++, or the equiv of a delegate in .net, so I can use hooks? The functions will have something like the following prototype: void hook(void* data) That's my c implamentation, but it would be similar. On another note, thanks for the help, both jamal and brandon. Haven't heard from you in forever, hows things going? Thanks, Tyler Littlefield Web: tysdomain.com email: tyler@xxxxxxxxxxxxx My programs don't have bugs, they're called randomly added features. ----- Original Message ----- From: "Jamal Mazrui" <empower@xxxxxxxxx> To: <program-l@xxxxxxxxxxxxx> Sent: Tuesday, March 24, 2009 9:08 AM Subject: [program-l] Re: quick python questionYou can use the eval function to evaluate an expression, or in your example, the exec statement to execute a statement (Python draws a distinction between an expression and a statement). Note that use of such techniques can risk security if there is a way for arbitrary code to be injected from an external source. Jamal On Mon, 23 Mar 2009, Tyler Littlefield wrote:Date: Mon, 23 Mar 2009 21:57:49 -0600 From: Tyler Littlefield <tyler@xxxxxxxxxxxxx> Reply-To: program-l@xxxxxxxxxxxxx To: program-l@xxxxxxxxxxxxx Subject: [program-l] quick python question Hello list, I'm working on a mud that uses python as it's scripting language, and had a quick question. Is it possible to evaluate python code? Like, from within the mud I'd like to do something like: eval (find_char("azar")).level=100 and have azar's level be set to 100. Thanks, Tyler Littlefield Web: tysdomain.com email: tyler@xxxxxxxxxxxxx My programs don't have bugs, they're called randomly added features.** To leave the list, click on the immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] ** If this link doesn't work then send a message to: ** program-l-request@xxxxxxxxxxxxx ** and in the Subject line type ** unsubscribe ** For other list commands such as vacation mode, click on the ** immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] ** or send a message, to ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq** To leave the list, click on the immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] ** If this link doesn't work then send a message to: ** program-l-request@xxxxxxxxxxxxx ** and in the Subject line type ** unsubscribe ** For other list commands such as vacation mode, click on the ** immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] ** or send a message, to ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq-- Doug Lee dgl@xxxxxxxx http://www.dlee.orgSSB BART Group doug.lee@xxxxxxxxxxxxxxxx http://www.ssbbartgroup.comThe very smart may feel they have nothing to learn from anyone; The very wise will find something to learn from everyone. (7/14/01) ** To leave the list, click on the immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] ** If this link doesn't work then send a message to: ** program-l-request@xxxxxxxxxxxxx ** and in the Subject line type ** unsubscribe ** For other list commands such as vacation mode, click on the ** immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] ** or send a message, to** program-l-request@xxxxxxxxxxxxx with the Subject:- faq
** To leave the list, click on the immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] ** If this link doesn't work then send a message to: ** program-l-request@xxxxxxxxxxxxx ** and in the Subject line type ** unsubscribe ** For other list commands such as vacation mode, click on the ** immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] ** or send a message, to ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq