Skip to content

Commit 1f0048b

Browse files
committed
First commit
0 parents  commit 1f0048b

11 files changed

+501
-0
lines changed

IDL/.clang-format

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright 2016 Nidium Inc. All rights reserved.
2+
# Use of this source code is governed by a MIT license
3+
# that can be found in the LICENSE file.
4+
5+
# BasedOnStyle: WebKit
6+
AccessModifierOffset: -4
7+
#AlignAfterOpenBracket: true
8+
#AlignConsecutiveAssignments: true
9+
AlignEscapedNewlinesLeft: true
10+
#AlignOperands: true
11+
AlignTrailingComments: true
12+
AllowAllParametersOfDeclarationOnNextLine: true
13+
AllowShortBlocksOnASingleLine: false
14+
#AllowShortCaseLabelsOnASingleLine: false
15+
AllowShortFunctionsOnASingleLine: None
16+
AllowShortIfStatementsOnASingleLine: true
17+
AllowShortLoopsOnASingleLine: false
18+
#AlwaysBreakAfterDefinitionReturnType: None
19+
AlwaysBreakBeforeMultilineStrings: true
20+
AlwaysBreakTemplateDeclarations: true
21+
#BinPackArguments: true
22+
#BinPackParameters: false
23+
BreakBeforeBinaryOperators: false
24+
BreakBeforeBraces: GNU
25+
BreakBeforeTernaryOperators: true
26+
BreakConstructorInitializersBeforeComma: false
27+
ColumnLimit: 80
28+
CommentPragmas: '^ IWYU pragma:'
29+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
30+
ConstructorInitializerIndentWidth: 4
31+
ContinuationIndentWidth: 4
32+
Cpp11BracedListStyle: false
33+
DerivePointerAlignment: false
34+
DisableFormat: false
35+
ExperimentalAutoDetectBinPacking: false
36+
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
37+
IndentCaseLabels: true
38+
IndentWidth: 4
39+
IndentWrappedFunctionNames: false
40+
KeepEmptyLinesAtTheStartOfBlocks: true
41+
#MacroBlockBegin: ''
42+
#MacroBlockEnd: ''
43+
MaxEmptyLinesToKeep: 2
44+
NamespaceIndentation: None
45+
#ObjCBlockIndentWidth: 4
46+
ObjCSpaceAfterProperty: true
47+
ObjCSpaceBeforeProtocolList: true
48+
PenaltyBreakBeforeFirstCallParameter: 19
49+
PenaltyBreakComment: 300
50+
PenaltyBreakFirstLessLess: 120
51+
PenaltyBreakString: 1000
52+
PenaltyExcessCharacter: 1000000
53+
PenaltyReturnTypeOnItsOwnLine: 60
54+
PointerAlignment: Right
55+
#SpaceAfterCStyleCast: false
56+
SpaceBeforeAssignmentOperators: true
57+
SpaceBeforeParens: ControlStatements
58+
SpaceInEmptyParentheses: false
59+
SpacesBeforeTrailingComments: 1
60+
SpacesInAngles: false
61+
SpacesInContainerLiterals: true
62+
SpacesInCStyleCastParentheses: false
63+
SpacesInParentheses: false
64+
#SpacesInSquareBrackets: false
65+
Standard: Cpp11
66+
TabWidth: 8
67+
UseTab: Never

IDL/JSRobot.cpp

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
Copyright 2016 Nidium Inc. All rights reserved.
3+
Use of this source code is governed by a MIT license
4+
that can be found in the LICENSE file.
5+
*/
6+
7+
8+
#include "JSRobot.h"
9+
#include <Binding/ClassMapper.h>
10+
11+
12+
namespace Nidium {
13+
namespace Binding {
14+
15+
// {{{ Start Constructor
16+
JSRobot *JSRobot::Constructor(JSContext *cx, JS::CallArgs &args,
17+
JS::HandleObject obj)
18+
{
19+
unsigned argc = args.length();
20+
unsigned argcMin = ((1 > argc) ? (argc) : (1));
21+
22+
switch (argcMin)
23+
{
24+
case 1:
25+
{
26+
/* Start argument conversion */
27+
/* Handle argument #0 of type "cstring" */
28+
if (args[0].isNull())
29+
{
30+
JS_ReportError(cx, "TypeError");
31+
return nullptr;
32+
}
33+
//.. cstring
34+
JS::RootedString __curstr(cx, JS::ToString(cx, args[0]));
35+
if (!__curstr)
36+
{
37+
JS_ReportError(cx, "TypeError");
38+
return nullptr;
39+
}
40+
JSAutoByteString __curstr_c;
41+
__curstr_c.encodeUtf8(cx, __curstr);
42+
43+
char *inArg_0 = __curstr_c.ptr();
44+
45+
/* End of argument conversion */
46+
47+
JSRobot *n_JSRobot = new JSRobot(inArg_0);
48+
49+
return n_JSRobot;
50+
break;
51+
}
52+
default:
53+
JS_ReportError(cx, "TypeError: wrong number of arguments");
54+
return nullptr;
55+
break;
56+
}
57+
58+
return nullptr;
59+
}
60+
// }}} End Constructor
61+
62+
// {{{ Methods
63+
// List normal methods
64+
JSFunctionSpec *JSRobot::ListMethods()
65+
{
66+
static JSFunctionSpec funcs[] = { CLASSMAPPER_FN(JSRobot, echo, 1),
67+
68+
JS_FS_END };
69+
70+
return funcs;
71+
}
72+
73+
74+
// Methods implementation
75+
// {{{ Start method echo
76+
bool JSRobot::JS_echo(JSContext *cx, JS::CallArgs &args)
77+
{
78+
unsigned argc = args.length();
79+
unsigned argcMin = ((1 > argc) ? (argc) : (1));
80+
81+
switch (argcMin)
82+
{
83+
case 1:
84+
{
85+
/* Start argument conversion */
86+
/* Handle argument #0 of type "cstring" */
87+
if (args[0].isNull())
88+
{
89+
JS_ReportError(cx, "TypeError");
90+
return false;
91+
}
92+
93+
//.. cstring
94+
JS::RootedString __curstr(cx, JS::ToString(cx, args[0]));
95+
if (!__curstr)
96+
{
97+
JS_ReportError(cx, "TypeError");
98+
return false;
99+
}
100+
JSAutoByteString __curstr_c;
101+
__curstr_c.encodeUtf8(cx, __curstr);
102+
103+
char *inArg_0 = __curstr_c.ptr();
104+
105+
106+
/* End of argument conversion */
107+
108+
this->echo(inArg_0);
109+
break;
110+
}
111+
default:
112+
JS_ReportError(cx, "TypeError: wrong number of arguments");
113+
return false;
114+
break;
115+
}
116+
117+
return true;
118+
}
119+
// }}} End method echo
120+
121+
// }}} End Methods
122+
123+
// {{{ Registration
124+
void JSRobot::RegisterObject(JSContext *cx)
125+
{
126+
127+
JSRobot::ExposeClass(cx, "Robot");
128+
}
129+
// }}}
130+
131+
} // namespace Binding
132+
} // namespace Nidium

IDL/JSRobot.h

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright 2016 Nidium Inc. All rights reserved.
3+
Use of this source code is governed by a MIT license
4+
that can be found in the LICENSE file.
5+
*/
6+
7+
#include "JSRobotBase.h"
8+
#include <Binding/ClassMapper.h>
9+
#include <Binding/JSUtils.h>
10+
#include <Core/Utils.h>
11+
12+
#ifndef binding_JSRobot_h__
13+
#define binding_JSRobot_h__
14+
15+
namespace Nidium {
16+
namespace Binding {
17+
18+
class JSRobot : public ClassMapper<JSRobot>, public JSRobotBase
19+
{
20+
public:
21+
JSRobot(char *name) : JSRobotBase(name) { }
22+
23+
// Constructor
24+
static JSRobot *Constructor(JSContext *cx, JS::CallArgs &args,
25+
JS::HandleObject obj);
26+
// Listings
27+
static JSFunctionSpec *ListMethods();
28+
// Registration
29+
static void RegisterObject(JSContext *cx);
30+
31+
protected:
32+
NIDIUM_DECL_JSCALL(echo);
33+
};
34+
} // namespace Binding
35+
} // namespace Nidium
36+
37+
#endif

IDL/JSRobotBase.cpp

Whitespace-only changes.

IDL/JSRobotBase.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class JSRobotBase
2+
{
3+
public:
4+
JSRobotBase(char *name) : m_Name(strdup(name)) { }
5+
6+
~JSRobotBase() {
7+
free(m_Name);
8+
}
9+
10+
protected:
11+
void echo(char *str) {
12+
printf("%s : says \"%s\"\n", m_Name, str);
13+
}
14+
15+
private:
16+
char *m_Name = nullptr;
17+
};

IDL/Robot.idl

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
Constructor(cstring name),
3+
className=Robot,
4+
exposed=class
5+
] interface Robot
6+
{
7+
void echo(cstring data);
8+
};

IDL/main.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <Core/Context.h>
2+
#include <Binding/NidiumJS.h>
3+
#include <ape_netlib.h>
4+
#include "JSRobot.h"
5+
6+
unsigned long _ape_seed = time(NULL) ^ (getpid() << 16);
7+
8+
using namespace Nidium::Core;
9+
using namespace Nidium::Binding;
10+
11+
int main() {
12+
ape_global *net = APE_init();
13+
Context ctx(net);
14+
NidiumJS *njs = ctx.getNJS();
15+
16+
JSRobot::RegisterObject(njs->getJSContext());
17+
18+
njs->LoadScript("../robot.js");
19+
}

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
To build and run code samples :
2+
```
3+
./build.sh
4+
```

0 commit comments

Comments
 (0)