From a484879b14fd7b078a5a4989c2f2ada0ee269bfb Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 10 Jun 2023 12:18:58 +0800 Subject: [PATCH] ... --- docs/quick-start/attr.md | 4 ++-- docs/quick-start/call.md | 4 ++-- docs/quick-start/interop.md | 6 +++--- docs/quick-start/modules.md | 10 ++++++++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/docs/quick-start/attr.md b/docs/quick-start/attr.md index 5318736e..5da2d63b 100644 --- a/docs/quick-start/attr.md +++ b/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. \ No newline at end of file diff --git a/docs/quick-start/call.md b/docs/quick-start/call.md index 7ac472ec..6f621035 100644 --- a/docs/quick-start/call.md +++ b/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 diff --git a/docs/quick-start/interop.md b/docs/quick-start/interop.md index e09a96c3..28929826 100644 --- a/docs/quick-start/interop.md +++ b/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)` \ No newline at end of file ++ `void check_type(PyObject* obj, Type type)` ++ `void check_non_tagged_type(PyObject* obj, Type type)` \ No newline at end of file diff --git a/docs/quick-start/modules.md b/docs/quick-start/modules.md index 1d982941..3a8c76ff 100644 --- a/docs/quick-start/modules.md +++ b/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)); }; -``` \ No newline at end of file +``` + +### 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. \ No newline at end of file