in reply to Re^7: XS: SvPVLV examples?
in thread XS: SvPVLV examples?
I wonder if each variables with ext magic has its own virtual table pointer.
It does! That means that having only one extension type is not as limiting as it seems!
use strict; use warnings; use Inline C => <<'__EOI__'; static const char* test1_str = "Hello, "; static int test1_mg_get(pTHX_ SV *sv, MAGIC *mg) { sv_setpvn(sv, test1_str, (STRLEN)strlen(test1_str)); return 0; } static const MGVTBL vtbl_test1 = { test1_mg_get, NULL, NULL, NULL, NULL }; SV* get_test1_var() { SV* sv = newSV_type(SVt_PVLV); sv_magicext(sv, NULL, PERL_MAGIC_ext, &vtbl_test1, NULL, 0); return sv; } static const char* test2_str = "World!"; static int test2_mg_get(pTHX_ SV *sv, MAGIC *mg) { sv_setpvn(sv, test2_str, (STRLEN)strlen(test2_str)); return 0; } static const MGVTBL vtbl_test2 = { test2_mg_get, NULL, NULL, NULL, NULL }; SV* get_test2_var() { SV* sv = newSV_type(SVt_PVLV); sv_magicext(sv, NULL, PERL_MAGIC_ext, &vtbl_test2, NULL, 0); return sv; } __EOI__ use Devel::Peek qw( Dump ); my $test1 = get_test1_var(); my $test2 = get_test2_var(); print("$test1$test2\n");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: XS: SvPVLV examples?
by BrowserUk (Patriarch) on Sep 25, 2009 at 03:50 UTC | |
by ikegami (Patriarch) on Sep 25, 2009 at 04:05 UTC |