Skip to content

Commit e427eb2

Browse files
committed
COMMON: update V_FUNC callback to take return var arg
1 parent a895897 commit e427eb2

File tree

7 files changed

+44
-37
lines changed

7 files changed

+44
-37
lines changed

src/common/blib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2908,7 +2908,7 @@ void cmd_call_vfunc() {
29082908
if (code_peek() == kwTYPE_LEVEL_BEGIN) {
29092909
code_skipnext();
29102910
}
2911-
v_func->v.fn.cb(map);
2911+
v_func->v.fn.cb(map, NULL);
29122912
if (code_peek() == kwTYPE_LEVEL_END) {
29132913
code_skipnext();
29142914
}

src/common/eval.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ static inline void eval_var(var_t *r, var_t *var_p) {
748748
if (prog_error) {
749749
return;
750750
}
751+
751752
switch (var_p->type) {
752753
case V_INT:
753754
r->type = V_INT;
@@ -770,7 +771,7 @@ static inline void eval_var(var_t *r, var_t *var_p) {
770771
v_set(r, var_p);
771772
break;
772773
case V_FUNC:
773-
var_p->v.fn.cb(r);
774+
var_p->v.fn.cb(var_p, r);
774775
break;
775776
case V_NIL:
776777
r->type = V_NIL;

src/include/var.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extern "C" {
4747
#endif
4848

4949
struct var_s;
50-
typedef void (*method) (struct var_s *self);
50+
typedef void (*method) (struct var_s *self, struct var_s *retval);
5151

5252
typedef struct var_s {
5353
union {

src/platform/console/image.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ ImageBuffer *load_xpm_image(char **data) {
253253
//
254254
// png.clip(10, 10, 10, 10)
255255
//
256-
void cmd_image_clip(var_s *self) {
256+
void cmd_image_clip(var_s *self, var_s *) {
257257
var_int_t left, top, right, bottom;
258258
ImageBuffer *image = load_image(self);
259259
if (par_massget("iiii", &left, &top, &right, &bottom) == 4) {
@@ -298,7 +298,7 @@ void cmd_image_clip(var_s *self) {
298298
// end
299299
// png.filter(use colorToAlpha(x))
300300
//
301-
void cmd_image_filter(var_s *self) {
301+
void cmd_image_filter(var_s *self, var_s *) {
302302
ImageBuffer *image_buffer = load_image(self);
303303
if (code_peek() == kwUSE && image_buffer != NULL) {
304304
code_skipnext();
@@ -340,7 +340,7 @@ void cmd_image_filter(var_s *self) {
340340
// png2 = image(w, h)
341341
// png2.paste(png1, 0, 0)
342342
//
343-
void cmd_image_paste(var_s *self) {
343+
void cmd_image_paste(var_s *self, var_s *) {
344344
var_int_t x, y;
345345
var_t *var;
346346
ImageBuffer *image = load_image(self);
@@ -384,7 +384,7 @@ void cmd_image_paste(var_s *self) {
384384
// png.save("horse1.png")
385385
// png.save(#1)
386386
//
387-
void cmd_image_save(var_s *self) {
387+
void cmd_image_save(var_s *self, var_s *) {
388388
ImageBuffer *image = load_image(self);
389389
dev_file_t *filep = NULL;
390390
byte code = code_peek();

src/ui/form.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void FormLink::clicked(int x, int y, bool pressed) {
116116
}
117117
}
118118

119-
void cmd_form_close(var_s *self) {
119+
void cmd_form_close(var_s *self, var_s *) {
120120
g_system->getOutput()->removeInputs();
121121
g_system->getOutput()->resetScroll();
122122

@@ -129,7 +129,7 @@ void cmd_form_close(var_s *self) {
129129
v_free(&arg);
130130
}
131131

132-
void cmd_form_refresh(var_s *self) {
132+
void cmd_form_refresh(var_s *self, var_s *) {
133133
var_t arg;
134134
v_init(&arg);
135135
eval(&arg);
@@ -138,7 +138,7 @@ void cmd_form_refresh(var_s *self) {
138138
g_system->getOutput()->updateInputs(self, setVars);
139139
}
140140

141-
void cmd_form_do_events(var_s *self) {
141+
void cmd_form_do_events(var_s *self, var_s *) {
142142
// apply any variable changes onto attached widgets
143143
if (g_system->isRunning()) {
144144
AnsiWidget *out = g_system->getOutput();

src/ui/image.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ ImageBuffer *load_xpm_image(char **data) {
301301
return result;
302302
}
303303

304-
void cmd_image_show(var_s *self) {
304+
void cmd_image_show(var_s *self, var_s *) {
305305
ImageDisplay image;
306306
image._bid = map_get_int(self, IMG_BID, -1);
307307

@@ -351,12 +351,12 @@ void cmd_image_show(var_s *self) {
351351
}
352352
}
353353

354-
void cmd_image_hide(var_s *self) {
354+
void cmd_image_hide(var_s *self, var_s *) {
355355
int id = map_get_int(self, IMG_ID, -1);
356356
g_system->getOutput()->removeImage(id);
357357
}
358358

359-
void cmd_image_save(var_s *self) {
359+
void cmd_image_save(var_s *self, var_s *) {
360360
unsigned id = map_get_int(self, IMG_BID, -1);
361361
ImageBuffer *image = nullptr;
362362
List_each(ImageBuffer *, it, cache) {

src/ui/window.cpp

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,23 @@ StringList *get_items() {
6060
return items;
6161
}
6262

63-
void cmd_window_select_screen1(var_s *self) {
63+
void cmd_window_select_screen1(var_s *self, var_s *) {
6464
g_system->getOutput()->selectScreen(USER_SCREEN1);
6565
}
6666

67-
void cmd_window_select_screen2(var_s *self) {
67+
void cmd_window_select_screen2(var_s *self, var_s *) {
6868
g_system->getOutput()->selectScreen(USER_SCREEN2);
6969
}
7070

71-
void cmd_window_select_screen3(var_s *self) {
71+
void cmd_window_select_screen3(var_s *self, var_s *) {
7272
g_system->getOutput()->selectScreen(TEXT_SCREEN);
7373
}
7474

75-
void cmd_window_show_keypad(var_s *self) {
75+
void cmd_window_show_keypad(var_s *self, var_s *) {
7676
maShowVirtualKeyboard();
7777
}
7878

79-
void cmd_window_inset(var_s *self) {
79+
void cmd_window_inset(var_s *self, var_s *) {
8080
var_int_t x, y, w, h;
8181
par_massget("IIII", &x, &y, &w, &h);
8282
if (!prog_error) {
@@ -91,7 +91,7 @@ void cmd_window_inset(var_s *self) {
9191
}
9292
}
9393

94-
void cmd_window_set_font(var_s *self) {
94+
void cmd_window_set_font(var_s *self, var_s *) {
9595
var_num_t size;
9696
var_int_t bold, italic;
9797
char *unit = NULL;
@@ -103,27 +103,29 @@ void cmd_window_set_font(var_s *self) {
103103
pfree(unit);
104104
}
105105

106-
void cmd_window_set_size(var_s *self) {
106+
void cmd_window_set_size(var_s *self, var_s *) {
107107
var_int_t width, height;
108108
par_massget("II", &width, &height);
109109
g_system->setWindowSize(width, height);
110110
}
111111

112-
void cmd_window_get_theme(var_s *self) {
113-
EditTheme theme;
114-
theme.setId(g_themeId);
115-
v_init(self);
116-
map_init(self);
117-
map_set_int(self, "background", -theme._background);
118-
map_set_int(self, "text1", -theme._color);
119-
map_set_int(self, "text2", -theme._syntax_text);
120-
map_set_int(self, "text3", -theme._syntax_comments);
121-
map_set_int(self, "text4", -theme._syntax_command);
122-
map_set_int(self, "text5", -theme._syntax_statement);
123-
map_set_int(self, "text6", -theme._syntax_digit);
112+
void cmd_window_get_theme(var_s *, var_s *retval) {
113+
if (retval != nullptr) {
114+
EditTheme theme;
115+
theme.setId(g_themeId);
116+
v_init(retval);
117+
map_init(retval);
118+
map_set_int(retval, "background", -theme._background);
119+
map_set_int(retval, "text1", -theme._color);
120+
map_set_int(retval, "text2", -theme._syntax_text);
121+
map_set_int(retval, "text3", -theme._syntax_comments);
122+
map_set_int(retval, "text4", -theme._syntax_command);
123+
map_set_int(retval, "text5", -theme._syntax_statement);
124+
map_set_int(retval, "text6", -theme._syntax_digit);
125+
}
124126
}
125127

126-
void cmd_window_alert(var_s *self) {
128+
void cmd_window_alert(var_s *self, var_s *) {
127129
StringList *items = get_items();
128130
if (!prog_error && items->size() > 0) {
129131
const char *message = items->size() > 0 ? (*items)[0]->c_str() : "";
@@ -133,25 +135,29 @@ void cmd_window_alert(var_s *self) {
133135
delete items;
134136
}
135137

136-
void cmd_window_ask(var_s *self) {
138+
void cmd_window_ask(var_s *self, var_s *retval) {
137139
StringList *items = get_items();
138140
if (!prog_error && items->size() > 0) {
139141
const char *message = items->size() > 0 ? (*items)[0]->c_str() : "";
140142
const char *title = items->size() > 1 ? (*items)[1]->c_str() : "";
141-
map_set_int(self, WINDOW_ASK_RTN, g_system->ask(title, message, false));
143+
int result = g_system->ask(title, message, false);
144+
map_set_int(self, WINDOW_ASK_RTN, result);
145+
if (retval != nullptr) {
146+
v_setint(retval, result);
147+
}
142148
}
143149
delete items;
144150
}
145151

146-
void cmd_window_menu(var_s *self) {
152+
void cmd_window_menu(var_s *self, var_s *) {
147153
StringList *items = get_items();
148154
if (!prog_error && items->size() > 0) {
149155
g_system->optionsBox(items);
150156
}
151157
delete items;
152158
}
153159

154-
void cmd_window_message(var_s *self) {
160+
void cmd_window_message(var_s *self, var_s *) {
155161
var_t arg;
156162
v_init(&arg);
157163
eval(&arg);

0 commit comments

Comments
 (0)