I used to do this to get a program of an external class in c:
... push_text("Someclass"); SAFE_APPLY_MASTER("resolv", 1);
if (((struct svalue *)(Pike_sp - 1))->type != PIKE_T_PROGRAM) { Pike_error("Could not resolv program Someclass.\n"); } prog = ((struct svalue *)(Pike_sp - 1))->u.program; ...
However this does not work for me anymore when I try to resolv a Class that is defined inside the pmod that corresponds to the cmod (in my case in Public.Parser.JSON2 where Public.Parser.___JSON2 is the cmod).
Any ideas how to do that?
arne
to make it clear:
the text I push to resolve the class is the full name, in my case: "Public.Parser.JSON2.True".
I used to do this to get a program of an external class in c:
... push_text("Someclass"); SAFE_APPLY_MASTER("resolv", 1);
if (((struct svalue *)(Pike_sp - 1))->type != PIKE_T_PROGRAM) { Pike_error("Could not resolv program Someclass.\n"); } prog = ((struct svalue *)(Pike_sp - 1))->u.program; ...
However this does not work for me anymore when I try to resolv a
Class
that is defined inside the pmod that corresponds to the cmod (in my case in Public.Parser.JSON2 where Public.Parser.___JSON2 is the
cmod).
I used to do this to get a program of an external class in c:
... push_text("Someclass"); SAFE_APPLY_MASTER("resolv", 1);
if (((struct svalue *)(Pike_sp - 1))->type != PIKE_T_PROGRAM) { Pike_error("Could not resolv program Someclass.\n"); } prog = ((struct svalue *)(Pike_sp - 1))->u.program;
The reason you run into a problem is probably that the program you attempt to resolve uses the parent pointer, so you get a T_FUNCTION rather than a T_PROGRAM. For what purpose do you need the program pointer? For some purposes, program.c:program_from_svalue() may return something you can use. You may also want to have a look at object.c:parent_clone_object().
arne
I used to do this to get a program of an external class in c:
... push_text("Someclass"); SAFE_APPLY_MASTER("resolv", 1);
if (((struct svalue *)(Pike_sp - 1))->type != PIKE_T_PROGRAM) { Pike_error("Could not resolv program Someclass.\n"); } prog = ((struct svalue *)(Pike_sp - 1))->u.program;
The reason you run into a problem is probably that the program you attempt to resolve uses the parent pointer, so you get a T_FUNCTION rather than a T_PROGRAM. For what purpose do you need the program pointer? For some purposes, program.c:program_from_svalue() may return something you can use. You may also want to have a look at object.c:parent_clone_object().
arne
I need to create a Public.Parser.JSON2.True object in the parse() function. The parse function itself resides in Public.Parser.___JSON2.
I need to create a Public.Parser.JSON2.True object in the parse() function. The parse function itself resides in Public.Parser.___JSON2.
Sort of unrelated to the technicalities, but shouldn't that be a Public.Parser.JSON2.true (singleton) object? Likely of the class Public.Parser.JSON2.True though. But perhaps that was what you meant?
I need to create a Public.Parser.JSON2.True object in the parse() function. The parse function itself resides in
Public.Parser.___JSON2.
Sort of unrelated to the technicalities, but shouldn't that be a Public.Parser.JSON2.true (singleton) object? Likely of the class Public.Parser.JSON2.True though. But perhaps that was what you meant?
Yes, youre right. But somehow I have some problems resolving 'Public.Parser.JSON2.true' etc. Do I need something other than
APPLY_MASTER("resolv", 1);
?
Something like
push_text("Public"); SAFE_APPLY_MASTER("resolv", 1); push_text("Parser"); f_index(2); push_text("JSON2"); f_index(2); push_text("true"); f_index(2);
possibly.
I used to do this to get a program of an external class in c:
... push_text("Someclass"); SAFE_APPLY_MASTER("resolv", 1);
if (((struct svalue *)(Pike_sp - 1))->type != PIKE_T_PROGRAM) { Pike_error("Could not resolv program Someclass.\n"); } prog = ((struct svalue *)(Pike_sp - 1))->u.program;
The reason you run into a problem is probably that the program you attempt to resolve uses the parent pointer, so you get a T_FUNCTION rather than a T_PROGRAM. For what purpose do you need the program pointer? For some purposes, program.c:program_from_svalue() may return something you can use. You may also want to have a look at object.c:parent_clone_object().
I added a print_svalue for debugging and is gives me the name of the program i was looking up. Printing its type gives me type 4 (T_FUNCTION). Now I tried using program_from_svalue but it gives me the following error:
Parent lost, cannot clone program. /usr/lib/pike/modules/Public.pmod/Parser.pmod/JSON2.pmod/module.pmod:0: Public.Parser.JSON2->parse("Parent lost, cannot clone program.\n")
Is that because the parse function is not running in object context?
The reason you run into a problem is probably that the program you attempt to resolve uses the parent pointer, so you get a T_FUNCTION rather than a T_PROGRAM. For what purpose do you need the program pointer? For some purposes, program.c:program_from_svalue() may return something you can use. You may also want to have a look at object.c:parent_clone_object().
I added a print_svalue for debugging and is gives me the name of the program i was looking up. Printing its type gives me type 4 (T_FUNCTION). Now I tried using program_from_svalue but it gives me the following error:
Parent lost, cannot clone program. /usr/lib/pike/modules/Public.pmod/Parser.pmod/JSON2.pmod/module.pmod:0: Public.Parser.JSON2->parse("Parent lost, cannot clone program.\n")
Is that because the parse function is not running in object context?
Correct, as I said above, you probably want to use parent_clone_object() (or just call the svalue directly). Do you actually need the program pointer for something?
The reason you run into a problem is probably that the program you attempt to resolve uses the parent pointer, so you get a T_FUNCTION rather than a T_PROGRAM. For what purpose do you need the program pointer? For some purposes, program.c:program_from_svalue() may return something you can use. You may also want to have a look at object.c:parent_clone_object().
I added a print_svalue for debugging and is gives me the name of the program i was looking up. Printing its type gives me type 4 (T_FUNCTION). Now I tried using program_from_svalue but it gives me the following error:
Parent lost, cannot clone program. /usr/lib/pike/modules/Public.pmod/Parser.pmod/JSON2.pmod/module.pmod:0: Public.Parser.JSON2->parse("Parent lost, cannot clone program.\n")
Is that because the parse function is not running in object context?
Correct, as I said above, you probably want to use parent_clone_object() (or just call the svalue directly). Do you actually need the program pointer for something?
I need it to create an object of that program. I am a little confused though. If there is a simpler solution to create an object from the name of the program (const char*) i would like to know :-).
Correct, as I said above, you probably want to use parent_clone_object() (or just call the svalue directly). Do you actually need the program pointer for something?
I need it to create an object of that program. I am a little confused though. If there is a simpler solution to create an object from the name of the program (const char*) i would like to know :-).
In that case, something like:
push_text("Someclass"); APPLY_MASTER("resolv", 1); if (UNSAFE_IS_ZERO(Pike_sp - 1)) { Pike_error("Could not resolve program Someclass.\n"); } ref_push_*(arg1); ref_push_*(arg2); ... ref_push_*(argn); apply_svalue(Pike_sp - (n + 1), n); stack_pop_keep_top(1); /* Pop the resolved value */
/* Pike_sp-1 now (probably) contains the new object. */
probably does what you need.
Correct, as I said above, you probably want to use parent_clone_object() (or just call the svalue directly). Do you actually need the program pointer for something?
I need it to create an object of that program. I am a little
confused
though. If there is a simpler solution to create an object from the name of the program (const char*) i would like to know :-).
In that case, something like:
push_text("Someclass"); APPLY_MASTER("resolv", 1); if (UNSAFE_IS_ZERO(Pike_sp - 1)) { Pike_error("Could not resolve program Someclass.\n"); } ref_push_*(arg1); ref_push_*(arg2); ... ref_push_*(argn); apply_svalue(Pike_sp - (n + 1), n); stack_pop_keep_top(1); /* Pop the resolved value */
/* Pike_sp-1 now (probably) contains the new object. */
probably does what you need.
thats exactly what i needed. and it works. thanks!
pike-devel@lists.lysator.liu.se