Skip to content

Commit 71ae939

Browse files
authored
fix macro issue for mcpp and adapt for d2x 0.1.1 (#2)
* fix macro issue for mcpp and adapt for d2x 0.1.1 - mcpp-community/OpenOrg#1 Signed-off-by: sunrisepeak <speakshen@163.com> * update readme * update readme --------- Signed-off-by: sunrisepeak <speakshen@163.com>
1 parent 4bb08a8 commit 71ae939

15 files changed

Lines changed: 231 additions & 268 deletions

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
- d2x工具可以直接识别和加载
1919
- 提供了项目依赖描述, 支持一键配置环境
2020

21+
## 快速开始
22+
23+
- 第一步: 点击 [新建教程模板](https://github.com/new?template_name=d2x-project-template&template_owner=d2learn) 按钮, 通过模板仓库创建新教程项目
24+
- 第二步: 克隆新仓库到本地 - `git clone git@github.com:your_name/your_repo_name.git`
25+
- 第三步:
26+
- [安装d2x工具](https://d2learn.github.io/d2x-project-template/chapter_1.html)
27+
- [认识项目结构并配置](https://d2learn.github.io/d2x-project-template/chapter_2.html)
28+
2129
## 具体项目案例
2230

2331
| 项目 | 简介 | 备注 |

book/src/chapter_1.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ TODO...
4343

4444
### 创建项目
4545

46+
**通过模块创建(推荐)**
47+
48+
点击 [新建教程模板](https://github.com/new?template_name=d2x-project-template&template_owner=d2learn) 按钮, 通过模板仓库创建新教程项目. 然后, 再把生成的仓库clone到本地
49+
50+
```bash
51+
git clone git@github.com:your_name/your_repo_name.git
52+
```
53+
54+
**本地创建**
55+
4656
通过`d2x new xxx`命令创建一个新项目
4757

4858
```
@@ -51,7 +61,7 @@ d2x new d2hello
5161

5262
命令运行后会生成一个叫`d2hello`的目录, 进入/打开这个目录就能看到项目的基础结构
5363

54-
## 测试
64+
### 测试
5565

5666
进入新创建项目的根目录, 运行命令进行测试完整性
5767

book/src/chapter_2.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ d2x类项目是一种强调交互的教程类项目, 他通常由 `[Book + Video
2828
├── config.xlings
2929
├── d2x
3030
├── dslings ////// Code: 项目练习代码目录
31-
│ ├── hello-mcpp.cpp // 具体的练习代码
32-
│ ├── helloworld.cpp
31+
│ ├── hellomcpp.cpp // 具体的练习代码
32+
│ ├── hellocpp.cpp
3333
│ └── xmake.lua // 练习代码编排和配置文件
3434
├── LICENSE
3535
├── README.md
@@ -148,20 +148,19 @@ d2x checker
148148
根据控制台报错, 修复代码并观察控制台的变化. 下面是控制台的信息解释
149149

150150
```
151-
🌏Progress: [>----------] 0/10 -->> 显示当前的练习进度
151+
🌏 ▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 0/2 -->> 显示当前的练习进度
152+
153+
✗ hellocpp -->> 当前显示检测状态和练习名
154+
+ → dslings/hellocpp.cpp -->> 当前练习的文件路径
155+
156+
[ 23%]: cache compiling.release dslings/hellocpp.cpp -->> 显示编译状态
157+
error: dslings/hellocpp.cpp:29:39: error: found ':' in nested-name-specifier, expected '::'
158+
29 | std::cout << "hello, mcpp!" << std:endl; // 0.修复这个编译错误
159+
| ^
160+
| ::
161+
▼ 5 more lines below...
152162
153-
[Target: 00-0-hello-mcpp] - normal -->> 当前的练习名
154-
155-
❌ Error: Compilation/Running failed for dslings/hello-mcpp.cpp -->> 显示检测状态
156-
157-
The code exist some error!
158-
159-
---------C-Output--------- - 编译器输出信息
160-
[HONLY LOGW]: main: dslings/hello-mcpp.cpp:24 - ❌ | a == 1.1 (1 == 1.100000) -->> 错误提示及位置(24行)
161-
[HONLY LOGW]: main: dslings/hello-mcpp.cpp:26 - 🥳 Delete the D2X_WAIT to continue...
162-
163-
164-
AI: xxx -->> AI提示(需要配置大模型的key, 可不使用)
163+
🤖: AI Disabled / 未启用 - https://github.com/d2learn/d2x -->> 显示AI状态/信息(需要配置大模型的key, 可不使用)
165164
```
166165

167166
> 注: 退出检测程序使用`ctrl + c`
@@ -176,7 +175,7 @@ AI: xxx -->> AI提示(需要配置大模型的key, 可不使用)
176175
`dslings`目录创建`0-test.cpp`文件, 并添加如下内容
177176

178177
```cpp
179-
#include <d2x/cpp/common.hpp> // 辅助工具
178+
#include <d2x/cpp/d2x.hpp> // 辅助工具
180179

181180
#include <iosteam> // 故意写错测试 编译期检查
182181

@@ -185,7 +184,8 @@ int main() {
185184

186185
int a = 1;
187186
int b = 2;
188-
d2x_assert_eq(a, b); // 测试运行时检查
187+
188+
d2x::assert_eq(a, b); // 测试运行时检查
189189
}
190190
```
191191

@@ -209,10 +209,10 @@ target("0-test")
209209
由d2x工具支持的自动化代码练习项目, 通过在项目根目录下
210210
执行 d2x checker 进入"编译器驱动开发模式"的练习代码自动检测.
211211
需要用户根据控制台的报错和提示信息, 修改代码中的错误. 当修复所有编译错误和
212-
运行时检查点后, 你可以删除或注释掉代码中的 D2X_WAIT 宏, 会自动进入下一个练习.
213-
- D2X_WAIT: 该宏用于隔离不同练习, 你可以删除或注释掉该宏, 进入下一个练习.
214-
- d2x_assert_eq: 该宏用于运行时检查点, 你需要修复代码中的错误, 使得所有
215-
- D2X_YOUR_ANSWER: 该宏用于提示你需要修改的代码, 一般用于代码填空(即用正确的代码替换这个宏)
212+
运行时检查点后, 你可以删除或注释掉代码中的 d2x::wait(), 会自动进入下一个练习.
213+
- d2x::wait(): 用于隔离不同练习, 你可以删除或注释掉, 进入下一个练习.
214+
- d2x::assert_eq: 用于运行时检查点, 你需要修复代码中的错误, 使得所有
215+
- D2X_YOUR_ANSWER: 用于提示你需要修改的代码, 一般用于代码填空(即用正确的代码替换他)
216216

217217
## 其他功能 (可选)
218218

d2x/cpp/common.hpp

Lines changed: 0 additions & 46 deletions
This file was deleted.

d2x/cpp/common.lua

Lines changed: 0 additions & 29 deletions
This file was deleted.

d2x/cpp/d2x.hpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef D2X_HPP__D2X
2+
#define D2X_HPP__D2X
3+
4+
#include <iostream>
5+
#include <string>
6+
#include <source_location>
7+
#include <format>
8+
9+
namespace d2x {
10+
inline void wait(const std::source_location& loc = std::source_location::current()) {
11+
std::cout << std::format("\033[33m{}:{} - 🥳 D2X_WAIT: Delete the 'd2x::wait()' or '//d2x::wait()' to continue...\033[0m\n", loc.file_name(), loc.line());
12+
}
13+
14+
template <typename T1, typename T2>
15+
inline bool assert_eq(const T1& a, const T2& b, const std::string& msg = "",
16+
const std::source_location& loc = std::source_location::current()) {
17+
if (a != b) {
18+
std::cout << std::format("\033[31m{}:{} - ❌(error) | Assertion failed: {} != {}. {}\033[0m\n",
19+
loc.file_name(), loc.line(), a, b, msg);
20+
return false;
21+
}
22+
std::cout << std::format("\033[32m{}:{} - ✅ Assertion passed: {} == {}\033[0m\n",
23+
loc.file_name(), loc.line(), a, b);
24+
return true;
25+
}
26+
27+
inline bool assert_true(bool condition, const std::string& msg = "",
28+
const std::source_location& loc = std::source_location::current()) {
29+
if (!(condition)) {
30+
std::cout << std::format("\033[31m{}:{} - ❌(error) | Assertion failed: condition is false. {}\033[0m\n",
31+
loc.file_name(), loc.line(), msg);
32+
return false;
33+
}
34+
std::cout << std::format("\033[32m{}:{} - ✅ Assertion passed: condition is true\033[0m\n",
35+
loc.file_name(), loc.line());
36+
return true;
37+
}
38+
}
39+
40+
#endif

d2x/cpp/honly_logger.hpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

d2x/mcpp/common.cppm

Lines changed: 0 additions & 5 deletions
This file was deleted.

d2x/mcpp/d2x.cppm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module;
2+
3+
#include <d2x/cpp/d2x.hpp>
4+
5+
export module d2x;
6+
7+
import std;
8+
9+
export namespace d2x {
10+
using d2x::wait;
11+
using d2x::assert_eq;
12+
using d2x::assert_true;
13+
};

dslings/hello-mcpp.cpp

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)