module PyBind::Utils

Constants

BUILTIN_FUNCS
MODULE_SHORTCUTS

Public Instance Methods

False() click to toggle source
# File lib/pybind/utils.rb, line 32
def False
  LibPython.Py_False
end
None() click to toggle source
# File lib/pybind/utils.rb, line 24
def None
  LibPython.Py_None
end
True() click to toggle source
# File lib/pybind/utils.rb, line 28
def True
  LibPython.Py_True
end
callable?(pyobj) click to toggle source
# File lib/pybind/utils.rb, line 55
def callable?(pyobj)
  pystruct = pyobj.to_python_struct
  LibPython.PyCallable_Check(pystruct) == 1
end
decref(pyobj) click to toggle source
# File lib/pybind/utils.rb, line 66
def decref(pyobj)
  pystruct = pyobj.to_python_struct
  LibPython.Py_DecRef(pystruct)
  pystruct.send :pointer=, FFI::Pointer::NULL
  pyobj
end
eval(str) click to toggle source
# File lib/pybind/utils.rb, line 36
def eval(str)
  dict = main_dict
  eval_func = PyBind.builtin.get_attribute('eval')
  eval_func.call(str, dict, dict)
end
execfile(filename) click to toggle source
# File lib/pybind/utils.rb, line 42
def execfile(filename)
  dict = main_dict
  if PyBind.builtin.has_attribute?('execfile')
    execfile_func = PyBind.builtin.get_attribute('execfile')
    execfile_func.call(filename, dict, dict)
  else
    open_func = PyBind.builtin.get_attribute('open')
    exec_func = PyBind.builtin.get_attribute('exec')
    content = open_func.call(filename).get_attribute('read').call()
    exec_func.(content, dict, dict)
  end
end
incref(pyobj) click to toggle source
# File lib/pybind/utils.rb, line 60
def incref(pyobj)
  pystruct = pyobj.to_python_struct
  LibPython.Py_IncRef(pystruct)
  pyobj
end

Private Instance Methods

main_dict() click to toggle source
# File lib/pybind/utils.rb, line 75
def main_dict
  LibPython.PyModule_GetDict(PyBind.import("__main__").to_python_struct).to_ruby
end