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

Side by Side 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 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/ruby/appendix/signal_missing.c ('k') | tests/ruby/ruby.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 /* Copyright 2009 The Native Client Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can
3 * be found in the LICENSE file. */
4
5 #include <stdio.h>
6 #include <string.h>
7 #include <nacl/nacl_srpc.h>
8 #include "ruby-1.8.6-p368/ruby.h"
9
10 int initialized = 0;
11
12 char* INIT_RUBY_SCRIPT =
13 "$stdout_default = $stdout \n"
14 "class Logger \n"
15 " def initialize() \n"
16 " @strings = [] \n"
17 " end \n"
18 "\n"
19 " def write(s) \n"
20 " @strings.push(s) \n"
21 " $stdout_default.write s \n"
22 " end \n"
23 "\n"
24 " def get_string() \n"
25 " current = @strings \n"
26 " @strings = [] \n"
27 " return current.join("") \n"
28 " end \n"
29 "end \n"
30 "\n"
31 "$stdout_logger = Logger.new \n"
32 "$stdout = $stdout_logger \n";
33
34 /*
35 * Evals Ruby expression and returns stdout updates.
36 */
37 NaClSrpcError RubyEval(NaClSrpcChannel *channel,
38 NaClSrpcArg **in_args, NaClSrpcArg **out_args) {
39
40 /* TODO(krasin): MAKE IT THREAD-SAFE */
41 if (!initialized) {
42 ruby_init();
43 rb_eval_string(INIT_RUBY_SCRIPT);
44 initialized = 1;
45 }
46 rb_eval_string(in_args[0]->u.sval);
47 VALUE result = rb_eval_string("$stdout_logger.get_string()");
48
49 /*
50 * Strdup must be used because the SRPC layer frees the string passed to it.
51 */
52 out_args[0]->u.sval = strdup(StringValuePtr(result));
53
54 return NACL_SRPC_RESULT_OK;
55 }
56
57 /*
58 * Export the method as taking no arguments and returning one integer.
59 */
60 NACL_SRPC_METHOD("rubyEval:s:s", RubyEval);
OLDNEW
« 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