Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 54 lines (42 sloc) 1.084 kB
90caed2 @davisp Mark Emonk sources with the MIT license.
authored
1 // This file is part of Emonk released under the MIT license.
2 // See the LICENSE file for more information.
abef97c @davisp Refactoring C code. Futzing with return to Erlang.
authored
3
4 #include <string.h>
5
dcaeb47 @davisp Major rewrite of emonk for R14A.
authored
6 #include "util.h"
abef97c @davisp Refactoring C code. Futzing with return to Erlang.
authored
7
dcaeb47 @davisp Major rewrite of emonk for R14A.
authored
8 ENTERM
a7ddb18 @davisp Refactored to use one thread per context.
authored
9 util_mk_atom(ErlNifEnv* env, const char* atom)
abef97c @davisp Refactoring C code. Futzing with return to Erlang.
authored
10 {
dcaeb47 @davisp Major rewrite of emonk for R14A.
authored
11 ENTERM ret;
7bfe7ea @davisp Refactored to the NIF interface.
authored
12
8605de2 @davisp Now requires Erlang R14A or newer.
authored
13 if(enif_make_existing_atom(env, atom, &ret, ERL_NIF_LATIN1)) return ret;
abef97c @davisp Refactoring C code. Futzing with return to Erlang.
authored
14
7bfe7ea @davisp Refactored to the NIF interface.
authored
15 return enif_make_atom(env, atom);
16 }
abef97c @davisp Refactoring C code. Futzing with return to Erlang.
authored
17
dcaeb47 @davisp Major rewrite of emonk for R14A.
authored
18 ENTERM
a7ddb18 @davisp Refactored to use one thread per context.
authored
19 util_mk_ok(ErlNifEnv* env, ENTERM value)
7bfe7ea @davisp Refactored to the NIF interface.
authored
20 {
a7ddb18 @davisp Refactored to use one thread per context.
authored
21 ENTERM ok = util_mk_atom(env, "ok");
7bfe7ea @davisp Refactored to the NIF interface.
authored
22 return enif_make_tuple2(env, ok, value);
23 }
24
dcaeb47 @davisp Major rewrite of emonk for R14A.
authored
25 ENTERM
a7ddb18 @davisp Refactored to use one thread per context.
authored
26 util_mk_error(ErlNifEnv* env, const char* reason)
7bfe7ea @davisp Refactored to the NIF interface.
authored
27 {
a7ddb18 @davisp Refactored to use one thread per context.
authored
28 ENTERM error = util_mk_atom(env, "error");
29 return enif_make_tuple2(env, error, util_mk_atom(env, reason));
7bfe7ea @davisp Refactored to the NIF interface.
authored
30 }
31
32 void
a7ddb18 @davisp Refactored to use one thread per context.
authored
33 util_debug_jsval(JSContext* cx, jsval val)
7bfe7ea @davisp Refactored to the NIF interface.
authored
34 {
35 JSString* str;
36 char* bytes;
37
38 str = JS_ValueToString(cx, val);
39 if(!str)
abef97c @davisp Refactoring C code. Futzing with return to Erlang.
authored
40 {
7bfe7ea @davisp Refactored to the NIF interface.
authored
41 fprintf(stderr, "DEBUG: Unable to convert value.\n");
42 return;
abef97c @davisp Refactoring C code. Futzing with return to Erlang.
authored
43 }
44
7bfe7ea @davisp Refactored to the NIF interface.
authored
45 bytes = JS_EncodeString(cx, str);
46 if(!bytes)
47 {
48 fprintf(stderr, "DEBUG: Unable to encode string.\n");
49 return;
50 }
51
52 fprintf(stderr, "%s\n", bytes);
abef97c @davisp Refactoring C code. Futzing with return to Erlang.
authored
53 }
Something went wrong with that request. Please try again.