Skip to content

marciok/SwiftyRuby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

alt text SwiftyRuby

A proof of concept, on how to call Ruby from Swift, using CRuby package.


main.swift

import CRuby

ruby_setup()
rb_require("./hello_world/hello.rb") // Importing Ruby file

var stringArg = rb_str_new_cstr("Swift") // Creating new Ruby string
var result = rb_funcallv(0, rb_intern("hello"), 1, &(stringArg)) // Calling the function `hello` passing `stringArg`
var str = rb_string_value_cstr(&(result)) // Extracting the returned value as C string

print(String(cString: str))

ruby_cleanup(0)

hello.rb

def hello name
  "Hello #{name} from Ruby!"
end

Special thanks to @neonacho, who gave me some enlightenment

About

Calling Ruby from Swift

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published