This commit is contained in:
blueloveTH 2024-01-17 15:09:54 +08:00
parent 123c8a6a92
commit 3c5c536a05

View File

@ -48,7 +48,8 @@ struct PyLuaTable: PyLuaObject{
const PyLuaTable& self = _CAST(PyLuaTable&, obj); const PyLuaTable& self = _CAST(PyLuaTable&, obj);
LUA_PROTECTED( LUA_PROTECTED(
lua_rawgeti(_L, LUA_REGISTRYINDEX, self.r); lua_rawgeti(_L, LUA_REGISTRYINDEX, self.r);
lua_pushstring(_L, std::string(name.sv()).c_str()); std::string_view name_sv = name.sv();
lua_pushlstring(_L, name_sv.data(), name_sv.size());
lua_gettable(_L, -2); lua_gettable(_L, -2);
PyObject* ret = lua_popx_to_python(vm); PyObject* ret = lua_popx_to_python(vm);
lua_pop(_L, 1); lua_pop(_L, 1);
@ -60,7 +61,8 @@ struct PyLuaTable: PyLuaObject{
const PyLuaTable& self = _CAST(PyLuaTable&, obj); const PyLuaTable& self = _CAST(PyLuaTable&, obj);
LUA_PROTECTED( LUA_PROTECTED(
lua_rawgeti(_L, LUA_REGISTRYINDEX, self.r); lua_rawgeti(_L, LUA_REGISTRYINDEX, self.r);
lua_pushstring(_L, std::string(name.sv()).c_str()); std::string_view name_sv = name.sv();
lua_pushlstring(_L, name_sv.data(), name_sv.size());
lua_push_from_python(vm, val); lua_push_from_python(vm, val);
lua_settable(_L, -3); lua_settable(_L, -3);
lua_pop(_L, 1); lua_pop(_L, 1);
@ -71,7 +73,8 @@ struct PyLuaTable: PyLuaObject{
const PyLuaTable& self = _CAST(PyLuaTable&, obj); const PyLuaTable& self = _CAST(PyLuaTable&, obj);
LUA_PROTECTED( LUA_PROTECTED(
lua_rawgeti(_L, LUA_REGISTRYINDEX, self.r); lua_rawgeti(_L, LUA_REGISTRYINDEX, self.r);
lua_pushstring(_L, std::string(name.sv()).c_str()); std::string_view name_sv = name.sv();
lua_pushlstring(_L, name_sv.data(), name_sv.size());
lua_pushnil(_L); lua_pushnil(_L);
lua_settable(_L, -3); lua_settable(_L, -3);
lua_pop(_L, 1); lua_pop(_L, 1);
@ -237,9 +240,11 @@ void lua_push_from_python(VM* vm, PyObject* val){
case VM::tp_float.index: case VM::tp_float.index:
lua_pushnumber(_L, _CAST(f64, val)); lua_pushnumber(_L, _CAST(f64, val));
return; return;
case VM::tp_str.index: case VM::tp_str.index: {
lua_pushstring(_L, _CAST(CString, val)); std::string_view sv = _CAST(Str, val).sv();
lua_pushlstring(_L, sv.data(), sv.size());
return; return;
}
case VM::tp_tuple.index: { case VM::tp_tuple.index: {
lua_newtable(_L); lua_newtable(_L);
int i = 1; int i = 1;