Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use v6;
- use NativeCall;
- module Gumbo {
- class gumbo_node_t is repr('CPointer') {};
- class gumbo_output_t is repr('CPointer') {};
- class gumbo_vector_t is repr('CPointer') {};
- # typedef struct {
- # void** data;
- #
- # unsigned int length;
- #
- # unsigned int capacity;
- # } GumboVector;
- class gumbo_vector_s is repr('CStruct') {
- has OpaquePointer $.data;
- has uint $.length;
- has uint $.capacity;
- }
- # typedef struct GumboInternalOutput {
- # GumboNode* document;
- #
- # GumboNode* root;
- #
- # GumboVector /* GumboError */ errors;
- # } GumboOutput;
- #
- class gumbo_output_s is repr('CStruct') {
- has gumbo_node_t $.document;
- has gumbo_node_t $.root;
- has gumbo_vector_s $.errors;
- }
- #typedef struct {
- # GumboVector /* GumboNode* */ children;
- #
- # // True if there was an explicit doctype token as opposed to it being omitted.
- # bool has_doctype;
- #
- # // Fields from the doctype token, copied verbatim.
- # const char* name;
- # const char* public_identifier;
- # const char* system_identifier;
- #
- # GumboQuirksModeEnum doc_type_quirks_mode;
- # } GumboDocument;
- #
- class gumbo_document_s is repr('CStruct') {
- has gumbo_vector_s $.children;
- has int8 $.has_doctype;
- has str $.name;
- has str $.public_identifier;
- has str $.system_identifier;
- has int $.doc_type_quirks_mode;
- }
- sub gumbo_parse(Str) is native('libgumbo') returns gumbo_output_t { * }
- sub parse-html (Str $html) is export {
- my gumbo_output_t $gumbo_output = gumbo_parse($html);
- say nativesizeof(gumbo_output_s);
- say nativesizeof(gumbo_vector_s);
- say nativesizeof(OpaquePointer);
- my gumbo_output_s $go = nativecast(gumbo_output_s, $gumbo_output);
- say $go.perl;
- #say $go.root.perl;
- #my gumbo_vector_s $vec = $go.errors;
- #say $vec.perl;
- }
- }
- (gumbo.pl call parse-html("<html><head><title>piko</title></html>");)
- root@testperl6:~/piko# perl6 gumbo.pl
- 12
- 20
- 4
- gumbo_output_s.new(document => gumbo_node_t.new, root => gumbo_node_t.new, errors => gumbo_vector_s.new(data => Pointer.new(224520520), length => 692114188733142712, capacity => 103240360544))
Advertisement
Add Comment
Please, Sign In to add comment