[svn:parrot] r36515 - trunk/ext/Parrot-Embed/lib/Parrot
chromatic at svn.parrot.org
chromatic at svn.parrot.org
Tue Feb 10 02:08:35 UTC 2009
Author: chromatic
Date: Tue Feb 10 02:08:34 2009
New Revision: 36515
URL: https://trac.parrot.org/parrot/changeset/36515
Log:
[Parrot::Embed] Allowed multi-level namespaces in find_global(). Pass in a
string as the namespace name, and this code will split it on the '::'
delimiter. This is a temporary hack, but it's a decent one.
Modified:
trunk/ext/Parrot-Embed/lib/Parrot/Embed.xs
Modified: trunk/ext/Parrot-Embed/lib/Parrot/Embed.xs
==============================================================================
--- trunk/ext/Parrot-Embed/lib/Parrot/Embed.xs Tue Feb 10 01:33:16 2009 (r36514)
+++ trunk/ext/Parrot-Embed/lib/Parrot/Embed.xs Tue Feb 10 02:08:34 2009 (r36515)
@@ -130,15 +130,46 @@
real_interp = interp->interp;
p_global = Parrot_str_new_constant( real_interp, global );
- if ( items == 3 )
+ if (items == 3)
namespace = ST(2);
else
namespace = &PL_sv_undef;
if (namespace != &PL_sv_undef )
{
- p_namespace = Parrot_str_new_constant( real_interp, SvPVX(namespace) );
- pmc = Parrot_find_global_s(real_interp, p_namespace, p_global);
+ char *ns_copy = savepv(SvPV_nolen(namespace));
+ char *ns_str = ns_copy;
+ char *prev = ns_str;
+ PMC *ns = NULL;
+
+ while (*ns_str++)
+ {
+ STRING *ns_part;
+
+ if (! (*ns_str == ':' && *(ns_str + 1) == ':'))
+ continue;
+
+ *ns_str = 0;
+ ns_str += 2;
+
+ if (!ns)
+ ns = Parrot_find_global_cur(real_interp,
+ Parrot_str_new_constant(real_interp, prev));
+ else
+ ns = Parrot_find_global_n(real_interp, ns,
+ Parrot_str_new_constant(real_interp, prev));
+ prev = ns_str;
+ }
+
+ if (!ns)
+ ns = Parrot_find_global_cur(real_interp,
+ Parrot_str_new_constant(real_interp, prev));
+ else
+ ns = Parrot_find_global_n(real_interp, ns,
+ Parrot_str_new_constant(real_interp, prev));
+
+ pmc = Parrot_find_global_n(real_interp, ns, p_global);
+ Safefree(ns_copy);
}
else
pmc = Parrot_find_global_cur( real_interp, p_global );
More information about the parrot-commits
mailing list