Running Objective-C with Ruby on Rails

I want to execute the following Objective-C code in a Rails application:

CFMutableStringRef inputString = CFStringCreateMutableCopy(kCFAllocatorDefault, 32, CFSTR("")); CFLocaleRef locale = CFLocaleCreate(kCFAllocatorDefault, CFSTR("ru")); CFStringTransform(inputString, NULL, kCFStringTransformStripDiacritics, false); CFStringLowercase(inputString, locale); NSLog(@"%@", (NSString *)inputString); CFRelease(locale); CFRelease(inputString); 

It basically outputs a lowercase, non-contact version of the input string. I am running on a Snow Leopard server.

How can I do this (without using MacRuby, which seems to be redundant here)? I have heard about Ruby extensions, but cannot find any resources in my case.

+4
source share
2 answers

Instead of creating an application, you should turn on and off in one instance of Rails, you can write your application using other communication methods, for example, named pipes:

http://hints.macworld.com/article.php?story=20041025103920992 http://www.pauldix.net/2009/07/using-named-pipes-in-ruby-for-interprocess-communication.html

Or follow the Ruby C extension path:

http://ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html http://people.apache.org/~rooneg/talks/ruby-extensions/ruby-extensions.html

0
source

You may be able to do this with ffi , but for this you need to enter a set of functions. A tiny test case for calling a Core Foundation function:

 require 'ffi' module CF extend FFI::Library ffi_lib '/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation' attach_function :CFAbsoluteTimeGetCurrent, [], :double end puts CF.CFAbsoluteTimeGetCurrent 
+1
source

Source: https://habr.com/ru/post/1381605/


All Articles