blueloveTH 2 năm trước cách đây
mục cha
commit
62024cb132
1 tập tin đã thay đổi với 19 bổ sung2 xóa
  1. 19 2
      docs/quick-start/misc.md

+ 19 - 2
docs/quick-start/misc.md

@@ -1,6 +1,6 @@
 ---
 ---
 icon: dot
 icon: dot
-label: 'Misc'
+label: 'Miscellaneous'
 order: 0
 order: 0
 ---
 ---
 
 
@@ -9,15 +9,32 @@ order: 0
 Sometimes you need to use the following code to prevent the gc from collecting objects.
 Sometimes you need to use the following code to prevent the gc from collecting objects.
 
 
 ```cpp
 ```cpp
-auto _lock = vm->heap.gc_scope_lock()
+auto _lock = vm->heap.gc_scope_lock();
 ```
 ```
 
 
 The scope lock is required if you create a PyObject and then try to run python-level bytecodes.
 The scope lock is required if you create a PyObject and then try to run python-level bytecodes.
 
 
 For example, you create a temporary object on the stack and then call `vm->py_str`.
 For example, you create a temporary object on the stack and then call `vm->py_str`.
 
 
+```cpp
+void some_func(VM* vm){
+    PyObject* obj = VAR(List(5));
+    // unsafe
+    PyObject obj_string = vm->py_str(obj);
+}
+```
+
 Because users can have an overload of `__str__`, the call process is unsafe.
 Because users can have an overload of `__str__`, the call process is unsafe.
 
 
 When the vm is running python-level bytecodes, gc may start and delete your temporary object.
 When the vm is running python-level bytecodes, gc may start and delete your temporary object.
 
 
 The scope lock prevents this from happening.
 The scope lock prevents this from happening.
+
+```cpp
+void some_func(VM* vm){
+    PyObject* obj = VAR(List(5));
+    // safe
+    auto _lock = vm->heap.gc_scope_lock();
+    PyObject obj_string = vm->py_str(obj);
+}
+```