def testLfun(self): s = ldmud.Closure(self.master, "master_fun", self.master) self.assertIsNotNone(s) self.assertEqual(s(), 54321) s2 = ldmud.Closure(self.master, "master_fun", self.master) self.assertEqual(s2, s) self.assertIn(s2, set((s, )))
def testEfun(self): s = ldmud.Closure(self.master, "this_object") self.assertIsNotNone(s) self.assertEqual(s(), self.master) s2 = ldmud.Closure(self.master, "this_object") self.assertEqual(s2, s) self.assertIn(s2, set((s, )))
def receive_message(inter_ob, data, txt): global call_catch_tell if call_catch_tell is None: symbol_ob = ldmud.Symbol('ob') symbol_txt = ldmud.Symbol('txt') call_catch_tell = ldmud.efuns.unbound_lambda( ldmud.Array(( symbol_ob, symbol_txt, )), ldmud.Array( (ldmud.Closure(ldmud.get_master(), "efun::call_resolved"), ldmud.Array((ldmud.Closure(ldmud.get_master(), '&'), ldmud.Symbol('result'))), symbol_ob, "catch_tell", symbol_txt))) current_ob = ldmud.efuns.this_object() if current_ob == inter_ob or not ldmud.efuns.bind_lambda( call_catch_tell, current_ob)(inter_ob, txt): data.call_control_ob("receive_message", inter_ob, txt) if data.snooper is not None: try: ldmud.efuns.tell_object(data.snooper, "%" + txt) except: pass
def testLWOLfun(self): lwob = ldmud.LWObject("/testob") s = ldmud.Closure(lwob, "testfun", lwob) self.assertIsNotNone(s) self.assertEqual(s(42, "A", "B", "C"), 3) s2 = ldmud.Closure(lwob, "testfun", lwob) self.assertEqual(s2, s) self.assertIn(s2, set((s, )))
def testOperator(self): s = ldmud.Closure(self.master, ",") self.assertIsNotNone(s) with self.assertRaises(RuntimeError): s() s2 = ldmud.Closure(self.master, ",") self.assertEqual(s2, s) self.assertIn(s2, set((s, )))
def testLWOEfun(self): lwob = ldmud.LWObject("/testob") s = ldmud.Closure(lwob, "this_object") self.assertIsNotNone(s) self.assertEqual(s(), lwob) s2 = ldmud.Closure(lwob, "this_object") self.assertEqual(s2, s) self.assertIn(s2, set((s, )))
def lfun_call(ob, funname, *args): if hasattr(ob, "functions"): fun = getattr(ob.functions, funname, None) if fun is not None: argnum = len(fun.arguments) if argnum < len(args): args = args[:argnum] elif argnum > len(args): args += (argnum - len(args)) * (0, ) return fun(*args) else: return ldmud.Closure(ob, "efun::call_other")(ob, funname, *args)
def testOperator(self): s = ldmud.Closure(self.master, ",") self.assertIsNotNone(s) with self.assertRaises(RuntimeError): s()
def testDestructedLfun(self): ob = ldmud.Object("/testob") c = ldmud.Closure(ob, "testfun", ob) self.assertTrue(c) ldmud.efuns.destruct(ob) self.assertFalse(c)
def receive_input(event): global current_interactive try: os.read(signal_pipe[0], 1) except: pass if len(queue): (inter_ob, inp) = queue.pop(0) data = control.interactives.get(inter_ob, None) if data is None: return data.update_idle() ldmud.efuns.set_this_player(inter_ob) current_interactive = inter_ob try: if inp is not None: # Check for input_tos has_bang = len(inp) > 0 and inp[0] == '!' found = False for idx, it in enumerate(data.inputto): if not has_bang or (it.flag & INPUT_IGNORE_BANG): data.inputto.pop(idx) if isinstance(it.cb_fun, ldmud.Closure): it.cb_fun(inp, *it.args) else: util.lfun_call(it.cb_ob, it.cb_fun, inp, *it.args) found = True break # It is an action? if not found: if has_bang: inp = inp[1:] ldmud.Closure(inter_ob, "efun::command")(inp, inter_ob) # Now handle the prompt def print_prompt(prompt): if isinstance(prompt, ldmud.Closure): prompt = prompt() if not isinstance(prompt, str): return data.call_control_ob("receive_prompt", inter_ob, prompt) if data.snooper is not None: try: ldmud.efuns.tell_object(data.snooper, "%" + prompt) except: pass for it in data.inputto: print_prompt(it.prompt) return print_prompt(data.options.get(interactive.IC_PROMPT, '> ')) finally: current_interactive = None