Skip to content

Commit

Permalink
feat(melang): Eval supports path format character @
Browse files Browse the repository at this point in the history
  • Loading branch information
Water-Melon committed Nov 5, 2023
1 parent f893ddb commit 25b5c53
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/Melon Developer Guide.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3830,7 +3830,8 @@ Their definitions can be found in melon/include/mln_types.h.
mln_lang_var_t *init(mln_lang_ctx_t *);

<5> Eval(val, data, in_string, alias);
val - a file path or a code string.
val - a file path or a code string. If it is a path, the path format support '@' which means
that the new co-routine base directory is identical with the current co-routine's.
data - the data that we want to deliver to the new coroutine.
in_string - a optional argument. If is set and its value is *true*, *val* is a code string.
Otherwise, *val* is a file path.
Expand Down
18 changes: 16 additions & 2 deletions src/mln_lang.c
Original file line number Diff line number Diff line change
Expand Up @@ -6834,13 +6834,15 @@ static mln_lang_var_t *mln_lang_func_eval_process(mln_lang_ctx_t *ctx)
mln_string_t v2 = mln_string("data");
mln_string_t v3 = mln_string("in_string");
mln_string_t v4 = mln_string("alias");
mln_string_t data_name = mln_string("EVAL_DATA"), *dup, *alias;
mln_string_t data_name = mln_string("EVAL_DATA"), *dup, *alias, *path, tmp;
mln_lang_symbol_node_t *sym;
mln_lang_val_t *val1, *val2;
mln_s32_t type, type3;
mln_u32_t job_type;
mln_u8ptr_t data;
mln_lang_ctx_t *newctx;
char buf[1024], *p;
int n;
/*arg1*/
if ((sym = mln_lang_symbol_node_search(ctx, &v1, 1)) == NULL) {
ASSERT(0);
Expand Down Expand Up @@ -6902,8 +6904,20 @@ static mln_lang_var_t *mln_lang_func_eval_process(mln_lang_ctx_t *ctx)
mln_lang_errmsg(ctx, "Invalid type of argument 4.");
return NULL;
}
path = val1->data.s;
if (path->len && path->data[0] == '@' && ctx->filename != NULL && (p = strrchr((const char *)(ctx->filename->data), '/')) != NULL) {
n = sizeof(buf) - 1;
if (n > p - (char *)(ctx->filename->data)) {
n = p - (char *)(ctx->filename->data);
}
memcpy(buf, ctx->filename->data, n);
n += snprintf(buf + n, sizeof(buf) - n - 1, "/%s", (char *)(&(path->data[1])));
buf[n] = 0;
mln_string_nset(&tmp, buf, n);
path = &tmp;
}
/*create job ctx*/
if ((newctx = __mln_lang_job_new(ctx->lang, alias, job_type, val1->data.s, NULL, NULL)) == NULL) {
if ((newctx = __mln_lang_job_new(ctx->lang, alias, job_type, path, NULL, NULL)) == NULL) {
if ((ret_var = mln_lang_var_create_false(ctx, NULL)) == NULL) {
mln_lang_errmsg(ctx, "No memory.");
return NULL;
Expand Down

0 comments on commit 25b5c53

Please sign in to comment.