From e3fe104e7d5ec184aac36128aed2d217cb655dfc Mon Sep 17 00:00:00 2001 From: Florian Frank Date: Wed, 22 Sep 2010 22:21:02 +0200 Subject: started to build jruby extension with Rakefile --- java/src/json/ext/ParserService.java | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 java/src/json/ext/ParserService.java (limited to 'java/src/json/ext/ParserService.java') diff --git a/java/src/json/ext/ParserService.java b/java/src/json/ext/ParserService.java new file mode 100644 index 0000000..e0805a7 --- /dev/null +++ b/java/src/json/ext/ParserService.java @@ -0,0 +1,34 @@ +/* + * This code is copyrighted work by Daniel Luz . + * + * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files + * for details. + */ +package json.ext; + +import java.io.IOException; + +import org.jruby.Ruby; +import org.jruby.RubyClass; +import org.jruby.RubyModule; +import org.jruby.runtime.load.BasicLibraryService; + +/** + * The service invoked by JRuby's {@link org.jruby.runtime.load.LoadService LoadService}. + * Defines the JSON::Ext::Parser class. + * @author mernen + */ +public class ParserService implements BasicLibraryService { + public boolean basicLoad(Ruby runtime) throws IOException { + runtime.getLoadService().require("json/common"); + RuntimeInfo info = RuntimeInfo.initRuntime(runtime); + + info.jsonModule = runtime.defineModule("JSON"); + RubyModule jsonExtModule = info.jsonModule.defineModuleUnder("Ext"); + RubyClass parserClass = + jsonExtModule.defineClassUnder("Parser", runtime.getObject(), + Parser.ALLOCATOR); + parserClass.defineAnnotatedMethods(Parser.class); + return true; + } +} -- cgit v1.2.1