This commit is contained in:
blueloveTH 2024-01-16 11:04:20 +08:00
parent 2fd0732be5
commit 20b11c17cf

View File

@ -5,7 +5,8 @@ order: 17
---
pkpy provides a lua bridge to reuse lua bindings.
It allows you to run lua code and call lua functions in python.
It allows you to run lua code and call lua functions in python
by embed a lua virtual machine.
Add `lua_bridge.hpp` and `lua_bridge.cpp` in [3rd/lua_bridge](https://github.com/blueloveTH/pocketpy/tree/main/3rd/lua_bridge) to your project.
Make sure `lua.h`, `lualib.h` and `lauxlib.h` are in your include path
@ -47,6 +48,20 @@ class Table:
def __setattr__(self, key, value): ...
```
Only basic types can be passed between python and lua.
The following table shows the type mapping.
If you pass an unsupported type, an exception will be raised.
| Python Type | Lua Type |
| ----------- | -------- |
| None | nil |
| bool | boolean |
| int | number |
| float | number |
| str | string |
| lua.Table | table |
| lua.Function| function |
### Example
```cpp
#include "lua_bridge.hpp"