Top Mud Sites Forum

Top Mud Sites Forum (http://www.topmudsites.com/forums/index.php)
-   MUD Coding (http://www.topmudsites.com/forums/forumdisplay.php?f=9)
-   -   Advanced LPC question (http://www.topmudsites.com/forums/showthread.php?t=360)

Tamsyn@zebedee.org 07-17-2003 05:59 AM

OK, for you advanced LPC coders:
If I have a global string variable, say 't' in an object, I can
reference it's value within a closure:

f = lambda( ({}), ({#'write,({#'t}) }) );
funcall(t);

This will do write(t);
My question: Is it possible to dynamically specify/bind the name of the variable. I've tried various ways of using symbol_function() and quote() with no success, and my gut feeling is that it isn't possible.
Anyone have the definitive answer?

markizs 07-17-2003 07:29 AM


Tamsyn@zebedee.org 07-17-2003 07:31 AM

yes i did, thanks for pointing that out.

JilesDM 07-17-2003 07:02 PM

If you want to bind to an arbitrary global variable in the same object as the closure is being constructed in, it's simple:
[code] string x;
closure f;

x = whatever_variable_name;
f = lambda(({}),({#'write,({#'apply,symbol_variable(x) })}));
[/quote]

The key here is remembering to run the symbol returned by symbol_variable through apply or funcall.

Tamsyn@zebedee.org 07-21-2003 04:41 AM



All times are GMT -4. The time now is 05:21 AM.

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright Top Mud Sites.com 2022