blueloveTH пре 2 година
родитељ
комит
a484879b14
4 измењених фајлова са 15 додато и 9 уклоњено
  1. 2 2
      docs/quick-start/attr.md
  2. 2 2
      docs/quick-start/call.md
  3. 3 3
      docs/quick-start/interop.md
  4. 8 2
      docs/quick-start/modules.md

+ 2 - 2
docs/quick-start/attr.md

@@ -43,7 +43,7 @@ As you can see, direct access does not take care of derived attributes or method
 In most cases, what you need is `getattr` and `setattr`.
 These two methods handle all possible cases.
 
-#### `PyObject* VM::getattr(PyObject* obj, StrName name, bool throw_err=true)`
+#### `PyObject* getattr(PyObject* obj, StrName name, bool throw_err=true)`
 
 This method is equivalent to `getattr` in python.
 If the attribute is not found, it will return `nullptr`
@@ -64,7 +64,7 @@ int result = CAST(int, ret);
 std::cout << result << std::endl; // 3
 ```
 
-#### `void VM::setattr(PyObject*, StrName, PyObject*)`
+#### `void setattr(PyObject*, StrName, PyObject*)`
 
 This method is equivalent to `setattr` in python.
 It raises `TypeError` if the object does not support attribute assignment.

+ 2 - 2
docs/quick-start/call.md

@@ -10,8 +10,8 @@ You can use `call` to invoke any python callable object,
 including functions, methods, classes, etc.
 For methods, `call_method` can be used.
 
-+ `PyObject* VM::call(PyObject* obj, ...)`
-+ `PyObject* VM::call_method(PyObject* obj, StrName name, ...)`
++ `PyObject* call(PyObject* obj, ...)`
++ `PyObject* call_method(PyObject* obj, StrName name, ...)`
 
 ### Exmaple
 

+ 3 - 3
docs/quick-start/interop.md

@@ -79,7 +79,7 @@ List& list = CAST(List&, obj);
 ### Check type of `PyObject*`
 
 Each `PyObject*` has a `Type` field to indicate its type.
-`Type` is just an integer which is the global index in `VM::_all_types`.
+`Type` is just an integer which is the global index in `vm->_all_types`.
 
 `VM` class has a set of predefined `Type` constants for quick access.
 They are prefixed by `tp_`. For example, `tp_object`(object),
@@ -115,5 +115,5 @@ Other variants are designed for specific types and are faster.
 You can also use `check_` prefix functions assert the type of a `PyObject*`,
 which will throw `TypeError` on failure.
 
-+ `void VM::check_type(PyObject* obj, Type type)`
-+ `void VM::check_non_tagged_type(PyObject* obj, Type type)`
++ `void check_type(PyObject* obj, Type type)`
++ `void check_non_tagged_type(PyObject* obj, Type type)`

+ 8 - 2
docs/quick-start/modules.md

@@ -53,7 +53,7 @@ When you do `import` a module, the VM will try to find it in the following order
 
 1. Search `vm->_modules`, if found, return it.
 2. Search `vm->_lazy_modules`, if found, compile and execute it, then return it.
-3. Search the working directory and try to load it from file system via `vm->_import_handler`.
+3. Try `vm->_import_handler`.
 
 
 ### Customized import handler
@@ -76,4 +76,10 @@ inline Bytes _default_import_handler(const Str& name){
     fclose(fp);
     return Bytes(std::move(buffer));
 };
-```
+```
+
+### Import module via cpp
+
+You can use `vm->py_import` to import a module.
+This is equivalent to `import` in python.
+Return the module object if success.