aboutsummaryrefslogtreecommitdiff
path: root/web/callback.js
blob: 178b8e9f0a8d50090a00ab7b7362976d7460bd9c (plain)
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
addToLibrary({

cbfl: [],

validateCallbackId__deps: [ 'cbfl' ],
validateCallbackId: function(i) {
  if (i < 0) {
    console.log("--- WARNING ---");
    console.log("Trying to access callback function of invalid id " + i);
    console.log("--- WARNING ---");
    return false;
  }

  if (i >= _cbfl.length) {
    console.log("--- WARNING ---");
    console.log("Trying to access callback function " + i + ", but only "
      + _cbfl.length + " have been registered. This may be caused by a "
      + "call outside of the main thread.");
    console.log("--- WARNING ---");
    return false;
  }

  return true;
},

addCallbackFunction__deps: [ 'cbfl' ],
addCallbackFunction: function(f) {
  _cbfl.push(f)
  return _cbfl.length - 1
},

callFunction__deps: [ 'cbfl', 'validateCallbackId' ],
callFunction: function(id, arg) {
  if (_validateCallbackId(id))
    _cbfl[id](UTF8ToString(arg));
},

callFunctionInt__deps: [ 'cbfl', 'validateCallbackId' ],
callFunctionInt: function(id) {
  if (_validateCallbackId(id))
    return _cbfl[id]();
  return 0;
},

});

Generated with cgit - Back to sebastiano.tronto.net