Sha256: ae57e270631b9d3fa7caab95474d55b29d083f543e6cc6b2cbe8c9dc4a68dde0

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

module Gap
    class CFunc
        def initialize(sam = Gap::Main)
            @sam = sam
        end

        def gen(name, args, text)
            md5 = Gap::MD5.hexdigest(text)
            cpp = _file name + "_" + md5, ".cpp"
            outdll = _file name + "_" + md5, ".dll"
            dll = name + "_" + md5 + ".dll"
            output = @sam.genfile dll do
                @sam.writefile cpp, 
                    %{extern "C" int __stdcall #{name}(#{args}) {
#{text}
}}
                system "g++ #{cpp} -shared -static -s -m32 -o #{outdll} -Wl,-add-stdcall-alias"
                open(outdll, "rb") do |f| f.read end
            end
            Gap::DLL.new(dll)[name]
        end

        def genlib(name, text)
            md5 = Gap::MD5.hexdigest(text)
            cpp = _file name + "_" + md5, ".cpp"
            outdll = _file name + "_" + md5, ".dll"
            dll = name + "_" + md5 + ".dll"
            output = @sam.genfile dll do
                @sam.writefile cpp, 
                    %{#define GAPI(type) extern "C" type __stdcall
#{text}
}
                system "g++ #{cpp} -shared -static -s -m32 -o #{outdll} -Wl,-add-stdcall-alias"
                open(outdll, "rb") do |f| f.read end
            end
            Gap::DLL.new(dll)
        end

        DEFAULT_GEN = CFunc.new
        def self.gen(name, args, text)
            DEFAULT_GEN.gen name, args, text
        end

        def self.genlib(name, text)
            DEFAULT_GEN.genlib name, text
        end

        private
        def _file(name, ext = "")
            "temp/cfunc_" << name << ext
        end
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gap50-0.1.1 lib/gap50/gap/cfunc.rb
gap50-0.1.0 lib/gap50/gap/cfunc.rb