summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorOpportunityLiu <[email protected]>2019-07-02 10:59:21 +0800
committerOpportunityLiu <[email protected]>2019-07-02 10:59:21 +0800
commit10194ed2bc005211feba0c6d54924782b69f7fc6 (patch)
treec5a55dd159d72c2b439e9fdf328c82a3d6043c98 /core/src
parentb0c2771fd052116bf009788ab7fde3878ce6e3da (diff)
add file:__gc
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/io/file_close___gc.c (renamed from core/src/xmake/io/file_close.c)43
-rw-r--r--core/src/xmake/machine.c3
2 files changed, 37 insertions, 9 deletions
diff --git a/core/src/xmake/io/file_close.c b/core/src/xmake/io/file_close___gc.c
index e05f33861..26f584b9c 100644
--- a/core/src/xmake/io/file_close.c
+++ b/core/src/xmake/io/file_close___gc.c
@@ -15,14 +15,14 @@
* Copyright (C) 2015 - 2019, TBOOX Open Source Group.
*
* @author OpportunityLiu
- * @file file_close.c
+ * @file file_close___gc.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "file_close"
+#define TB_TRACE_MODULE_NAME "file_close___gc"
#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
@@ -35,10 +35,7 @@
* implementation
*/
-/*
- * file:close()
- */
-tb_int_t xm_io_file_close(lua_State* lua)
+static tb_int_t xm_io_file_close_impl(lua_State* lua, tb_bool_t allow_closed_file)
{
// check
tb_assert_and_check_return_val(lua, 0);
@@ -46,8 +43,12 @@ tb_int_t xm_io_file_close(lua_State* lua)
xm_io_file* file = xm_io_getfile(lua);
if (xm_io_file_is_closed(file))
{
- lua_pushboolean(lua, tb_true);
- xm_io_file_success();
+ if (allow_closed_file)
+ {
+ lua_pushboolean(lua, tb_true);
+ xm_io_file_success();
+ }else
+ xm_io_file_error_closed(lua);
}
if (xm_io_file_is_file(file))
{
@@ -74,3 +75,29 @@ tb_int_t xm_io_file_close(lua_State* lua)
xm_io_file_success();
}
}
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * interfaces
+ */
+
+/*
+ * file:close()
+ */
+tb_int_t xm_io_file_close(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ return xm_io_file_close_impl(lua, tb_false);
+}
+
+/*
+ * file:close()
+ */
+tb_int_t xm_io_file___gc(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ return xm_io_file_close_impl(lua, tb_true);
+}
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c
index 26734acfd..f09f941e1 100644
--- a/core/src/xmake/machine.c
+++ b/core/src/xmake/machine.c
@@ -105,6 +105,7 @@ tb_int_t xm_io_file_isatty(lua_State* lua);
tb_int_t xm_io_file_path(lua_State* lua);
tb_int_t xm_io_file___len(lua_State* lua);
tb_int_t xm_io_file___tostring(lua_State* lua);
+tb_int_t xm_io_file___gc(lua_State* lua);
// the path functions
tb_int_t xm_path_relative(lua_State* lua);
@@ -243,7 +244,7 @@ static luaL_Reg const g_io_file_functions[] =
, { "isatty", xm_io_file_isatty }
, { "path", xm_io_file_path }
, { "close", xm_io_file_close }
-, { "__gc", xm_io_file_close }
+, { "__gc", xm_io_file___gc }
, { "__len", xm_io_file___len }
, { "__tostring", xm_io_file___tostring }
, { tb_null, tb_null }