1 |
/* |
2 |
* Copyright (c) 2014 Christian Schoenebeck |
3 |
* |
4 |
* http://www.linuxsampler.org |
5 |
* |
6 |
* This file is part of LinuxSampler and released under the same terms. |
7 |
* See README file for details. |
8 |
*/ |
9 |
|
10 |
#ifndef LS_COREVMFUNCTIONS_H |
11 |
#define LS_COREVMFUNCTIONS_H |
12 |
|
13 |
#include "../common/global.h" |
14 |
#include "common.h" |
15 |
|
16 |
namespace LinuxSampler { |
17 |
|
18 |
class ScriptVM; |
19 |
|
20 |
class VMEmptyResult : public VMFnResult, public VMExpr { |
21 |
public: |
22 |
StmtFlags_t flags; |
23 |
|
24 |
VMEmptyResult() : flags(STMT_SUCCESS) {} |
25 |
ExprType_t exprType() const { return EMPTY_EXPR; } |
26 |
VMExpr* resultValue() { return this; } |
27 |
StmtFlags_t resultFlags() { return flags; } |
28 |
}; |
29 |
|
30 |
class VMStringResult : public VMFnResult, public VMStringExpr { |
31 |
public: |
32 |
StmtFlags_t flags; |
33 |
String value; |
34 |
|
35 |
VMStringResult() : flags(STMT_SUCCESS) {} |
36 |
String evalStr() { return value; } |
37 |
VMExpr* resultValue() { return this; } |
38 |
StmtFlags_t resultFlags() { return flags; } |
39 |
}; |
40 |
|
41 |
class VMEmptyResultFunction : public VMFunction { |
42 |
protected: |
43 |
ExprType_t returnType() { return EMPTY_EXPR; } |
44 |
VMFnResult* errorResult(); |
45 |
VMFnResult* successResult(); |
46 |
void wrnMsg(const String& txt); |
47 |
void errMsg(const String& txt); |
48 |
protected: |
49 |
VMEmptyResult result; |
50 |
}; |
51 |
|
52 |
class VMStringResultFunction : public VMFunction { |
53 |
protected: |
54 |
ExprType_t returnType() { return STRING_EXPR; } |
55 |
VMFnResult* errorResult(const String& s = ""); |
56 |
VMFnResult* successResult(const String& s = ""); |
57 |
protected: |
58 |
VMStringResult result; |
59 |
}; |
60 |
|
61 |
class CoreVMFunction_message : public VMEmptyResultFunction { |
62 |
public: |
63 |
int minRequiredArgs() const { return 1; } |
64 |
int maxAllowedArgs() const { return 1; } |
65 |
bool acceptsArgType(int iArg, ExprType_t type) const; |
66 |
ExprType_t argType(int iArg) const { return STRING_EXPR; } |
67 |
VMFnResult* exec(VMFnArgs* args); |
68 |
}; |
69 |
|
70 |
class CoreVMFunction_exit : public VMEmptyResultFunction { |
71 |
public: |
72 |
int minRequiredArgs() const { return 0; } |
73 |
int maxAllowedArgs() const { return 0; } |
74 |
bool acceptsArgType(int iArg, ExprType_t type) const { return false; } |
75 |
ExprType_t argType(int iArg) const { return INT_EXPR; /*whatever*/ } |
76 |
VMFnResult* exec(VMFnArgs* args); |
77 |
}; |
78 |
|
79 |
class CoreVMFunction_wait : public VMEmptyResultFunction { |
80 |
public: |
81 |
CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {} |
82 |
int minRequiredArgs() const { return 1; } |
83 |
int maxAllowedArgs() const { return 1; } |
84 |
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; } |
85 |
ExprType_t argType(int iArg) const { return INT_EXPR; } |
86 |
VMFnResult* exec(VMFnArgs* args); |
87 |
protected: |
88 |
ScriptVM* vm; |
89 |
}; |
90 |
|
91 |
} // namespace LinuxSampler |
92 |
|
93 |
#endif // LS_COREVMFUNCTIONS_H |