dl
dl_script_test.h
浏览该文件的文档.
1
11#pragma once
12
13#include "script/dl_script.h"
14
15namespace dl
16{
17 // 基础
18 constexpr std::string_view SCRIPT_TEST_BASE = R"(
19print "hello dl!"
20)";
21 // 表达式
22 constexpr std::string_view SCRIPT_TEST_EXPR = R"(
23a = 0
24b = 2
25c = 4
26d = 6
27print a + (b - c) * d / 3
28print "结果应该为-4"
29)";
30 // 字符串
31 constexpr std::string_view SCRIPT_TEST_STRING = R"(
32a = "hello"
33b = "dl"
34c = a + b
35print a+" "+b+"!"
36print c
37)";
38 // 断言
39 constexpr std::string_view SCRIPT_TEST_ASSERT = R"(
40a = 1
41assert a == 1
42assert a == 0
43)";
44 // 作用域
45 constexpr std::string_view SCRIPT_TEST_SCOPE = R"(
46a = 1
47{
48 b = 2
49 print a
50 print b
51 print c
52}
53{
54 c = 3
55 print a
56 print b
57 print c
58}
59print a
60print b
61print c
62)";
63 // vector
64 constexpr std::string_view SCRIPT_TEST_VECTOR = R"(
65a = 13
66vec = { 1,3, 5, 7 +1 ,9 *2,11}
67print vec
68)";
69 // function
70 constexpr std::string_view SCRIPT_TEST_FUNCTION = R"(
71function add(a, b)
72{
73 return a + b
74}
75print(add(2, 3))
76)";
77
78 inline void TestScript(std::string_view str)
79 {
80 ScriptBlock block = g_script->Compile(str);
81
82 ScriptVM vm;
83 vm.Execute(block);
84 }
85
96}
void Execute(const ScriptBlock &block)
dl脚本语言
constexpr std::string_view SCRIPT_TEST_FUNCTION
ScriptSystem * g_script
constexpr std::string_view SCRIPT_TEST_SCOPE
void TestScriptAll()
constexpr std::string_view SCRIPT_TEST_EXPR
constexpr std::string_view SCRIPT_TEST_BASE
constexpr std::string_view SCRIPT_TEST_STRING
void TestScript(std::string_view str)
constexpr std::string_view SCRIPT_TEST_ASSERT
constexpr std::string_view SCRIPT_TEST_VECTOR