diff options
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/io/file_close.c | 4 | ||||
| -rw-r--r-- | core/src/xmake/io/file_open.c | 5 |
2 files changed, 3 insertions, 6 deletions
diff --git a/core/src/xmake/io/file_close.c b/core/src/xmake/io/file_close.c index 6b4380bdf..98b2f1506 100644 --- a/core/src/xmake/io/file_close.c +++ b/core/src/xmake/io/file_close.c @@ -81,8 +81,8 @@ tb_int_t xm_io_file_close(lua_State* lua) tb_buffer_exit(&file->rcache); tb_buffer_exit(&file->wcache); - // exit file - tb_free(file); + // gc will free it if no any refs for lua_newuserdata() + // ... // ok lua_pushboolean(lua, tb_true); diff --git a/core/src/xmake/io/file_open.c b/core/src/xmake/io/file_open.c index 1c520a180..a342d4809 100644 --- a/core/src/xmake/io/file_open.c +++ b/core/src/xmake/io/file_open.c @@ -275,7 +275,7 @@ tb_int_t xm_io_file_open(lua_State* lua) } // make file - xm_io_file_t* file = tb_malloc0_type(xm_io_file_t); + xm_io_file_t* file = (xm_io_file_t*)lua_newuserdata(lua, sizeof(xm_io_file_t)); tb_assert_and_check_return_val(file, 0); // init file @@ -289,8 +289,5 @@ tb_int_t xm_io_file_open(lua_State* lua) // init the read/write line cache buffer tb_buffer_init(&file->rcache); tb_buffer_init(&file->wcache); - - // ok - lua_pushlightuserdata(lua, (tb_pointer_t)file); return 1; } |
