Minsky
dummy-addon.cc
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2021
3  @author Russell Standish
4  This file is part of Minsky.
5 
6  Minsky is free software: you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Minsky is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Minsky. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
21 #include <napi.h>
22 
23 #include <exception>
24 #include <iostream>
25 
26 using namespace Napi;
27 
28 
29 Value RESTCall(const Napi::CallbackInfo& info)
30 {
31  Env env = info.Env();
32  if (info.Length() < 1)
33  {
34  Napi::TypeError::New(env, "Needs to be call(endpoint[, arguments])").ThrowAsJavaScriptException();
35  return env.Null();
36  }
37 
38  try
39  {
40  return info[0];
41  }
42  catch (const std::exception& ex)
43  {
44  // throw C++ exception as Javascript exception
45  Napi::Error::New(env, ex.what()).ThrowAsJavaScriptException();
46  return env.Null();
47  }
48  catch (...)
49  {
50  Napi::Error::New(env, "unknown exception caught").ThrowAsJavaScriptException();
51  return env.Null();
52  }
53 }
54 
55 Object Init(Env env, Object exports) {
56  std::cout << "Init"<<std::endl;
57  exports.Set(String::New(env, "call"), Function::New(env, RESTCall));
58  return exports;
59 }
60 
61 NODE_API_MODULE(addon, Init)
62 
Value RESTCall(const Napi::CallbackInfo &info)
Definition: dummy-addon.cc:29
Object Init(Env env, Object exports)
Definition: dummy-addon.cc:55