Module: Perl::FFILib

Included in:
Perl
Defined in:
lib/perl/ffi_lib.rb

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/perl/ffi_lib.rb', line 3

def self.included(klass)
  klass.instance_eval do
    require 'perl/internal'
    extend FFI::Library

    Perl::FFILib::load(klass)

    # PERL_SYS_INIT3()
    attach_function 'Perl_sys_init3', [:int, :pointer, :pointer], :void
    # PERL_SYS_TERM()
    attach_function 'Perl_sys_term', [], :void

    klass.attach_function 'perl_alloc', [], :pointer
    attach_function 'perl_construct', [:pointer], :void
    # PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
    attach_function 'perl_parse', [:pointer, :pointer, :int, :pointer, :pointer], :void
    attach_function 'perl_run', [:pointer], :void
    attach_function 'perl_destruct', [:pointer], :void
    attach_function 'perl_free', [:pointer], :void

    # eval_pv()
    attach_function 'Perl_eval_pv', [:pointer, :string, :int], :pointer
    # call_pv()
    attach_function 'Perl_call_pv', [:pointer, :string, :int], :int
    # call_sv()
    attach_function 'Perl_call_sv', [:pointer, :pointer, :int], :int

    # ENTER()
    attach_function 'Perl_push_scope', [:pointer], :void
    # SAVETMPS()
    attach_function 'Perl_save_int', [:pointer, :pointer], :void
    # FREETMPS()
    attach_function 'Perl_free_tmps', [:pointer], :void
    # LEAVE()
    attach_function 'Perl_pop_scope', [:pointer], :void
    # PUSHMARK()
    attach_function 'Perl_markstack_grow', [:pointer], :void

    # newSV()
    attach_function 'Perl_newSVpv', [:pointer, :string, :int], :pointer

    attach_function 'Perl_newRV_noinc', [:pointer, :pointer], :pointer
    attach_function 'Perl_sv_2mortal', [:pointer, :pointer], :pointer

    attach_function 'Perl_newHV', [:pointer], :pointer
    # hv_store()
    attach_function 'Perl_hv_common_key_len', [:pointer, :pointer, :string, :int32, :int, :pointer, :uint32], :pointer

    attach_variable 'PL_curinterp', :pointer

    #
    # Returns a reference to internal information on the current
    # interpreter. Much of the public Perl API is in fact a thin
    # wrapper over data contained in here. A lot of damage can be
    # done my manipulating it incorrectly, so be careful.
    #
    def curinterp
      Perl::Internal.new(Perl.PL_curinterp)
    end
  end
end