FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
daScript/examples/tutorial/tutorial03.cpp at master · jamestiotio/daScript · GitHub
jamestiotio
/
daScript
Public
forked from
GaijinEntertainment/daScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
daScript
/
examples
/
tutorial
/
tutorial03.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
70 lines (60 loc) · 2.49 KB
Breadcrumbs
daScript
/
examples
/
tutorial
/
tutorial03.cpp
Copy path
File metadata and controls
70 lines (60 loc) · 2.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
"
daScript/daScript.h
"
using
namespace
das
;
//
example type, which we are going to expose to das
struct
Color
{
uint8_t
r, g, b, a;
float
luminance
()
const
{
return
0
.
2126f
*r +
0
.
7152f
*g +
0
.
0722f
*b; }
};
//
create type factory, so that type can be bound
MAKE_TYPE_FACTORY
(Color, Color);
//
create type annotation, which exposes it to C++
struct
ColorAnnotation
:
public
ManagedStructureAnnotation
<Color,
true
,
true
> {
ColorAnnotation
(ModuleLibrary & ml) : ManagedStructureAnnotation (
"
Color
"
, ml) {
//
expose individual fields
addField<
DAS_BIND_MANAGED_FIELD
(r)>(
"
r
"
);
addField<
DAS_BIND_MANAGED_FIELD
(g)>(
"
g
"
);
addField<
DAS_BIND_MANAGED_FIELD
(b)>(
"
b
"
);
addField<
DAS_BIND_MANAGED_FIELD
(a)>(
"
a
"
);
//
expose properties
addProperty<
DAS_BIND_MANAGED_PROP
(luminance)>(
"
luminance
"
);
}
virtual
bool
isLocal
()
const
override
{
return
true
; }
//
this ref-value can appear as local variable in das
virtual
bool
canCopy
()
const
override
{
return
true
; }
//
this ref-value can be copied
virtual
bool
canMove
()
const
override
{
return
true
; }
//
this ref-value can be moved
};
//
custom function, which takes type as an input, as well as returns it
Color
makeGray
(
const
Color & c ) {
uint8_t
lum =
uint8_t
(
min
( c.
luminance
(),
255
.
0f
) );
return
{ lum, lum, lum, c.
a
};
}
//
making custom builtin module
class
Module_Tutorial03
:
public
Module
{
public:
Module_Tutorial03
() : Module(
"
tutorial_03
"
) {
//
module name, when used from das file
ModuleLibrary
lib
(
this
);
lib.
addBuiltInModule
();
//
register custom type annotation
addAnnotation
(make_smart<ColorAnnotation>(lib));
//
note SimNode_ExtFuncCallAndCopyOrMove - this means function returns ref type value,
//
which needs to be copied or moved
addExtern<
DAS_BIND_FUN
(makeGray),SimNode_ExtFuncCallAndCopyOrMove>(*
this
, lib,
"
make_gray
"
,
SideEffects::none,
"
makeGray
"
);
}
};
//
registering module, so that its available via 'NEED_MODULE' macro
REGISTER_MODULE
(Module_Tutorial03);
#
define
TUTORIAL_NAME
"
/examples/tutorial/tutorial03.das
"
#
include
"
tutorial.inc
"
int
main
(
int
,
char
* [] ) {
//
request all da-script built in modules
NEED_ALL_DEFAULT_MODULES
;
//
request our custom module
NEED_MODULE
(Module_Tutorial03);
//
Initialize modules
Module::Initialize
();
//
run the tutorial
tutorial
();
//
shut-down daScript, free all memory
Module::Shutdown
();
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL