PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/erlv8_nif.erl

http://github.com/beamjs/erlv8
Erlang | 53 lines | 41 code | 12 blank | 0 comment | 0 complexity | 5bd39c3f0748a453de48eceaf63bb962 MD5 | raw file
 1-module(erlv8_nif).
 2-on_load(init/0).
 3
 4-export([init/0, new_vm/0, set_server/2, global/2, context/1, new_context/1,
 5         tick/3, stop/2, kill/1]).
 6
 7-define(DEFAULT_PREEMPTION, 100).
 8
 9init() ->
10    Preemption = 
11	case application:get_env(erlv8, preemption_ms) of
12	    {ok, V} ->
13		V;
14	    _ ->
15		?DEFAULT_PREEMPTION
16	end,
17    case os:getenv("ERLV8_SO_PATH") of
18	false ->
19	    case code:which(erlv8_nif) of
20		Filename when is_list(Filename) ->
21		    erlang:load_nif(filename:join([filename:dirname(Filename),"../priv/erlv8_drv"]), Preemption);
22		Err ->
23		    Err
24	    end;
25	Path ->
26	    Filename = filename:join([Path,"erlv8_drv"]),
27	    erlang:load_nif(Filename,Preemption)
28    end.
29
30
31new_vm() ->
32    error(not_loaded).
33
34set_server(_VMObject,_Pid) ->
35    error(not_loaded).
36
37context(_VMObject) ->
38    error(not_loaded).
39
40new_context(_VMObject) ->
41    error(not_loaded).
42
43global(_VMObject, _ContextObject) ->
44    error(not_loaded).
45
46tick(_VMObject, _Ref, _Tick) ->
47    error(not_loaded).
48
49stop(_VMObject, _Ref) ->
50    error(not_loaded).
51
52kill(_VMObject) ->
53    error(not_loaded).