This commit is contained in:
blueloveTH 2024-01-16 13:33:44 +08:00
parent c5ffaae2f4
commit 170744df82
2 changed files with 30 additions and 0 deletions

View File

@ -226,6 +226,33 @@ void lua_push_from_python(VM* vm, PyObject* val){
case VM::tp_str.index: case VM::tp_str.index:
lua_pushstring(_L, _CAST(CString, val)); lua_pushstring(_L, _CAST(CString, val));
return; return;
case VM::tp_tuple.index: {
lua_newtable(_L);
int i = 1;
for(PyObject* obj: PK_OBJ_GET(Tuple, val)){
lua_push_from_python(vm, obj);
lua_rawseti(_L, -2, i++);
}
return;
}
case VM::tp_list.index: {
lua_newtable(_L);
int i = 1;
for(PyObject* obj: PK_OBJ_GET(List, val)){
lua_push_from_python(vm, obj);
lua_rawseti(_L, -2, i++);
}
return;
}
case VM::tp_dict.index: {
lua_newtable(_L);
PK_OBJ_GET(Dict, val).apply([&](PyObject* key, PyObject* val){
lua_push_from_python(vm, key);
lua_push_from_python(vm, val);
lua_settable(_L, -3);
});
return;
}
} }
if(is_non_tagged_type(val, PyLuaTable::_type(vm))){ if(is_non_tagged_type(val, PyLuaTable::_type(vm))){

View File

@ -63,6 +63,9 @@ If you pass an unsupported type, an exception will be raised.
| `int` | `number` | YES | | `int` | `number` | YES |
| `float` | `number` | YES | | `float` | `number` | YES |
| `str` | `string` | YES | | `str` | `string` | YES |
| `tuple` | `table` | YES |
| `list` | `table` | YES |
| `dict` | `table` | YES |
| `lua.Table` | `table` | YES | | `lua.Table` | `table` | YES |
| `lua.Function`| `function`| NO | | `lua.Function`| `function`| NO |