Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Unified Diff: tests/ruby/main.c

Issue 440018: Ruby for NaCl. Please assign the appropriate reviewer. (Closed) Base URL: http://nativeclient.googlecode.com/svn/trunk/src/native_client/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/ruby/appendix/signal_missing.c ('k') | tests/ruby/ruby.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ruby/main.c
===================================================================
--- tests/ruby/main.c (revision 0)
+++ tests/ruby/main.c (revision 0)
@@ -0,0 +1,60 @@
+/* Copyright 2009 The Native Client Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can
+ * be found in the LICENSE file. */
+
+#include <stdio.h>
+#include <string.h>
+#include <nacl/nacl_srpc.h>
+#include "ruby-1.8.6-p368/ruby.h"
+
+int initialized = 0;
+
+char* INIT_RUBY_SCRIPT =
+ "$stdout_default = $stdout \n"
+ "class Logger \n"
+ " def initialize() \n"
+ " @strings = [] \n"
+ " end \n"
+ "\n"
+ " def write(s) \n"
+ " @strings.push(s) \n"
+ " $stdout_default.write s \n"
+ " end \n"
+ "\n"
+ " def get_string() \n"
+ " current = @strings \n"
+ " @strings = [] \n"
+ " return current.join("") \n"
+ " end \n"
+ "end \n"
+ "\n"
+ "$stdout_logger = Logger.new \n"
+ "$stdout = $stdout_logger \n";
+
+/*
+ * Evals Ruby expression and returns stdout updates.
+ */
+NaClSrpcError RubyEval(NaClSrpcChannel *channel,
+ NaClSrpcArg **in_args, NaClSrpcArg **out_args) {
+
+ /* TODO(krasin): MAKE IT THREAD-SAFE */
+ if (!initialized) {
+ ruby_init();
+ rb_eval_string(INIT_RUBY_SCRIPT);
+ initialized = 1;
+ }
+ rb_eval_string(in_args[0]->u.sval);
+ VALUE result = rb_eval_string("$stdout_logger.get_string()");
+
+ /*
+ * Strdup must be used because the SRPC layer frees the string passed to it.
+ */
+ out_args[0]->u.sval = strdup(StringValuePtr(result));
+
+ return NACL_SRPC_RESULT_OK;
+}
+
+/*
+ * Export the method as taking no arguments and returning one integer.
+ */
+NACL_SRPC_METHOD("rubyEval:s:s", RubyEval);
Property changes on: tests/ruby/main.c
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « tests/ruby/appendix/signal_missing.c ('k') | tests/ruby/ruby.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698