[ Pobierz całość w formacie PDF ]
.sv_setiv (SV*, int) Modifies an SV's values.The SV automatically gets rid ofsv_setnv (SV*, double) its old value and morphs to the new type.sv_setsv (SV* dest,sv_setsv copies the src SV to the dest SV afterSV* src)checking that the two pointers are different.sv_setpv (SV*, char *) String functions, which force the scalar to be a string ifsv_setpvn(SV*, char *, necessary.sv_setpv assumes a null-terminated string,int len while sv_setpvn takes the length.Both functions make asv_catpv (SV*, char*); copy of the given string.sv_catpvn(SV*, char*,The cat series of functions does string concatenation.int);sv_catsv (SV*, SV*);SVTYPE(SV*) Returns an enum value, and is equivalent to the reffunction.These are the common values listed in sv.h:SVt_IV (Integer) SVt_NV (Double)SVt_PV (String) SVt_RV (Reference)SVt_PVAV (Array) SVt_PVHV (Hash)SVt_PVCV (Code) SVt_PVGV (Glob)SVt_PVMG (Blessed or magical scalar) sv_setref_iv( Creates a new SV, sets it to the value i, and makes rvSV* rv, refer to this new SV.The other two functions are similar.char* classname,Note that sv_setref_pv stores the pointer; it does not makeint i)a copy of the string.(and similarly for nv and pv)If classname is nonnull, these functions bless thereference under that package.svREFCNT_dec(SV *) Decrements the reference count and calls sv_free if thiscount is 0.You should never call sv_free yourself.SV* sv_bless ( sv_bless blesses rv under a package represented bySV *rv, HV* stash); stash.Please refer to the section Section 20.3.4" for anint sv_isa(explanation of stashes.sv_isa returns 1 if it inherits from aSV *, char *pkgname);class pkgname.int sv_isobject(SV*);SV* sv_newmortal() By default, if you create an SV, you are responsible forSV* sv_2mortal(SV*) deleting it.If you create a mortal or temporary variable,SV* sv_mortalcopy(SV*) Perl automatically deletes it the end of the current scope(unless someone else holds a reference to it).sv_2mortal tags an existing SV as a mortal, andsv_2mortalcopy creates a mortal clone.SV* perl_get_sv( To get a scalar variable as you are used to seeing in scriptchar* varname, space, you have to explicitly bind an SV to a name.int create) create, if TRUE, forces it to create a variable if it didn'texist earlier.varname must always be qualified by thename of the package.To create $Foo::a, for example:SV *s = perl_get_av("Foo::a", 1);sv_dump(SV*) The name is a misnomer, since it is capable ofpretty-printing the contents of all Perl value types (castingthem to SV* if necessary).This is extremely useful if youhave Perl under a debugger: for example, inside gdb, usecall sv_dump(sv)The mortal series of calls in Table 20.1 create a temporary SV or tag an existing value as temporary.These calls essentially tell Perl to shove the SV onto a stack called tmps_stack and call svREFCNT_decon the SV at the end of the current scope.(More on this in the section "Inside Other Stacks.") Typically,all parameters passed between functions are tagged mortal, because neither the caller nor the calledfunction wants to worry about the appropriate time to delete the SV and its contents; Perl automaticallytakes care of the memory management.20.3.1.1 Using this API Perhaps your eyes are somewhat glazed and your mind is numbed, so we will relieve the tedium bywriting a custom interpreter using the API we have seen so far.(For now, this is our idea of fun!)Example 20.2 shows a function called create_envt_vars that creates a scalar variable for everyenvironment variable.Example 20.2: Creating Scalars for Environment Variables - the Hard Way!#include#includevoid create_envt_vars (char **environ){/** Each element in environ is in the form ="*/SV * sv = NULL;char **env = environ; /* for iterating through environ */char buf[1000]; /* will contain a copy of an envt variable */char *envt_var_name; /* Name of the envt.variable, like PATH */char *envt_var_value; /* Its corresponding value */char var_name[100]; /* Fully qualified name of environment var */while (*env) {strcpy (buf, *env);/* Search for "=", replace it with '\0', thus splitting it into* logical parts - envt variable name and the value*/envt_var_name = buf; envt_var_value = buf;while (*envt_var_value != '=') envt_var_value++;*envt_var_value++ = '\0';/* Qualify the environment var with the package name [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • personata.xlx.pl