forked from tum-vision/autonavx_skulpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv.js
135 lines (110 loc) · 4.17 KB
/
env.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
* Base namespace for Skulpt. This is the only symbol that Skulpt adds to the
* global namespace. Other user accessible symbols are noted and described
* below.
*/
var Sk = Sk || {};
/**
*
* Set various customizable parts of Skulpt.
*
* output: Replacable output redirection (called from print, etc.).
* read: Replacable function to load modules with (called via import, etc.)
* sysargv: Setable to emulate arguments to the script. Should be an array of JS
* strings.
* syspath: Setable to emulate PYTHONPATH environment variable (for finding
* modules). Should be an array of JS strings.
*
* Any variables that aren't set will be left alone.
*/
Sk.configure = function (options) {
'use strict';
Sk.output = options["output"] || Sk.output;
goog.asserts.assert(typeof Sk.output === "function");
Sk.debugout = options["debugout"] || Sk.debugout;
goog.asserts.assert(typeof Sk.debugout === "function");
Sk.read = options["read"] || Sk.read;
goog.asserts.assert(typeof Sk.read === "function");
Sk.timeoutMsg = options["timeoutMsg"] || Sk.timeoutMsg;
goog.asserts.assert(typeof Sk.timeoutMsg === "function");
goog.exportSymbol("Sk.timeoutMsg", Sk.timeoutMsg);
Sk.sysargv = options["sysargv"] || Sk.sysargv;
goog.asserts.assert(goog.isArrayLike(Sk.sysargv));
Sk.python3 = options["python3"] || Sk.python3;
goog.asserts.assert(typeof Sk.python3 === "boolean");
Sk.inputfun = options["inputfun"] || Sk.inputfun;
goog.asserts.assert(typeof Sk.inputfun === "function");
Sk.throwSystemExit = options["systemexit"] || false;
goog.asserts.assert(typeof Sk.throwSystemExit === "boolean");
Sk.retainGlobals = options["retainglobals"] || false;
goog.asserts.assert(typeof Sk.throwSystemExit === "boolean");
if (options["syspath"]) {
Sk.syspath = options["syspath"];
goog.asserts.assert(goog.isArrayLike(Sk.syspath));
// assume that if we're changing syspath we want to force reimports.
// not sure how valid this is, perhaps a separate api for that.
Sk.realsyspath = undefined;
Sk.sysmodules = new Sk.builtin.dict([]);
}
Sk.misceval.softspace_ = false;
};
goog.exportSymbol("Sk.configure", Sk.configure);
/*
* Replaceable message for message timeouts
*/
Sk.timeoutMsg = function () { return "Program exceeded run time limit."; };
goog.exportSymbol("Sk.timeoutMsg", Sk.timeoutMsg);
/*
* Replacable output redirection (called from print, etc).
*/
Sk.output = function (x) {};
/*
* Replacable function to load modules with (called via import, etc.)
* todo; this should be an async api
*/
Sk.read = function (x) { throw "Sk.read has not been implemented"; };
/*
* Setable to emulate arguments to the script. Should be array of JS strings.
*/
Sk.sysargv = [];
// lame function for sys module
Sk.getSysArgv = function () {
return Sk.sysargv;
};
goog.exportSymbol("Sk.getSysArgv", Sk.getSysArgv);
/**
* Setable to emulate PYTHONPATH environment variable (for finding modules).
* Should be an array of JS strings.
*/
Sk.syspath = [];
Sk.inBrowser = goog.global['document'] !== undefined || typeof goog.global['importScripts'] !== 'undefined';
/**
* Internal function used for debug output.
* @param {...} args
*/
Sk.debugout = function(args) {};
(function() {
// set up some sane defaults based on availability
if (goog.global['write'] !== undefined) {
Sk.output = goog.global['write'];
} else if (goog.global['console'] !== undefined && goog.global['console']['log'] !== undefined) {
Sk.output = function (x) {goog.global['console']['log'](x);};
} else if (goog.global['print'] !== undefined) {
Sk.output = goog.global['print'];
}
if (goog.global['print'] !== undefined) {
Sk.debugout = goog.global['print'];
}
}());
// override for closure to load stuff from the command line.
if (!Sk.inBrowser) {
goog.global.CLOSURE_IMPORT_SCRIPT = function(src) {
goog.global['eval'](goog.global['read']("support/closure-library/closure/goog/" + src));
return true;
};
}
Sk.python3 = false;
Sk.inputfun = function (args) { return prompt(args); };
goog.exportSymbol("Sk.python3",Sk.python3)
goog.exportSymbol("Sk.inputfun",Sk.inputfun)
goog.require("goog.asserts");