diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2011-04-20 15:24:11 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2011-04-20 15:24:11 +0200 |
commit | 9a7cd18cd11e0f435443c62fa68871768b98d248 (patch) | |
tree | 1e34d56e4f5ad7cd1908ab6155cbcd7fc60bdee5 /lib/efl/eet.rb | |
parent | 5a5e81dbf79ca4967b150ea4930255a2398ccab4 (diff) | |
download | ffi-efl-9a7cd18cd11e0f435443c62fa68871768b98d248.zip ffi-efl-9a7cd18cd11e0f435443c62fa68871768b98d248.tar.gz |
ffi-e17 renamed to ffi-efl
Diffstat (limited to 'lib/efl/eet.rb')
-rw-r--r-- | lib/efl/eet.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/efl/eet.rb b/lib/efl/eet.rb new file mode 100644 index 0000000..c9f0804 --- /dev/null +++ b/lib/efl/eet.rb @@ -0,0 +1,58 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +require 'efl/eet/eet-ffi' +# +module Efl + module Eet + # + class << self + # + def open path, mode=FILE_MODE_READ, &blk + if blk + f = Efl::API.eet_open path, mode + raise Exception.new "Unable to open file #{path}" if f.nil? + yield EetFile.new f + Efl::API.eet_close f + else + f = Efl::API.eet_open path, mode + return EetFile.new f unless f.nil? + end + end + end + # + class EetFile + # + def initialize ptr + @ptr=ptr + end + private :initialize + # + def close + Efl::API.eet_close @ptr + @ptr=nil + end + # + def mode_get + Efl::API.eet_mode_get @ptr + end + # + def write key, data, compress=false + Efl::API.eet_write @ptr, key, FFI::MemoryPointer.from_string(data), data.bytesize, ( compress ? 1 : 0 ) + end + # + def read key + ptr = FFI::MemoryPointer.new(:int) + data = Efl::API.eet_read @ptr, key, ptr + s = ptr.read_int + ptr.free + return nil if s==0 + ( data.null? ? nil : data.read_string[0..s-1] ) + end + # + end + # + end +end +# +# EOF |