lang: Add And for boolean
This commit is contained in:
parent
2c8ee2d3b7
commit
62dd71584f
2 changed files with 17 additions and 1 deletions
|
@ -42,8 +42,22 @@ static void boolean_invert(VmState state, Object obj, int priv) {
|
|||
vm_stack_set(state, 0, boolean_create(state, invert));
|
||||
}
|
||||
|
||||
static void boolean_and(VmState state, Object obj, int priv) {
|
||||
(void)priv;
|
||||
int arg_count = vm_stack_depth(state);
|
||||
vm_abort_if(state, arg_count != 2, "boolean_and requires one argument");
|
||||
Object arg = vm_stack_pop(state);
|
||||
bool value1 = boolean_value(state, obj);
|
||||
bool value2 = boolean_value(state, arg);
|
||||
bool anded = value1 && value2;
|
||||
Object new = boolean_create(state, anded);
|
||||
vm_stack_set(state, 0, new);
|
||||
object_drop(state, &arg);
|
||||
}
|
||||
|
||||
static struct object_call calls[] = {
|
||||
{.name = "Invert", .handler = boolean_invert, .priv = 0},
|
||||
{.name = "And", .handler = boolean_and, .priv = 0},
|
||||
{.name = NULL, /* end */}};
|
||||
|
||||
static struct object_class boolean_class = {
|
||||
|
|
|
@ -3,7 +3,9 @@ Use Another
|
|||
|
||||
Public Class Main Function BoolTest
|
||||
Set A To True
|
||||
Set B To A Invert
|
||||
Set B To False
|
||||
Set C To B Invert
|
||||
Set D To A And C
|
||||
Return B
|
||||
EndFunction
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue