Skip to content
Snippets Groups Projects
Commit a87cebdb authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Add User close() method

This can be used to force a close of the user.dat file, if open. Rather than
waiting for an out of scope User to get garbage-collected, this method could
be used to force a close of the user.dat file, if it's open.
parent 91f67dc7
Branches
Tags
1 merge request!463MRC mods by Codefenix (2024-10-20)
...@@ -1307,6 +1307,26 @@ js_get_time_left(JSContext *cx, uintN argc, jsval *arglist) ...@@ -1307,6 +1307,26 @@ js_get_time_left(JSContext *cx, uintN argc, jsval *arglist)
return JS_TRUE; return JS_TRUE;
} }
static JSBool
js_user_close(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
private_t* p;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((p=(private_t*)js_GetClassPrivate(cx, obj, &js_user_class))==NULL)
return JS_FALSE;
rc=JS_SUSPENDREQUEST(cx);
if(p->file > 0)
closeuserdat(p->file);
p->file = -1;
JS_RESUMEREQUEST(cx, rc);
return JS_TRUE;
}
static jsSyncMethodSpec js_user_functions[] = { static jsSyncMethodSpec js_user_functions[] = {
{"compare_ars", js_chk_ar, 1, JSTYPE_BOOLEAN, JSDOCSTR("string ars") {"compare_ars", js_chk_ar, 1, JSTYPE_BOOLEAN, JSDOCSTR("string ars")
...@@ -1346,6 +1366,10 @@ static jsSyncMethodSpec js_user_functions[] = { ...@@ -1346,6 +1366,10 @@ static jsSyncMethodSpec js_user_functions[] = {
"Note: for the pre-defined user object on the BBS, you almost certainly want bbs.get_time_left() instead.") "Note: for the pre-defined user object on the BBS, you almost certainly want bbs.get_time_left() instead.")
,31401 ,31401
}, },
{"close", js_user_close, 0, JSTYPE_VOID, JSDOCSTR("")
,JSDOCSTR("Close the <tt>user.dat</tt> file, if open. The file will be auto-reopened if necessary.")
,31902
},
{0} {0}
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment