2 Copyright (C) 2005-2008, The Perl Foundation.
7 pmc/luaboolean.pmc - Lua Boolean
11 C<LuaBoolean> extends C<LuaAny> to provide a class with the behaviour of
12 the Lua C<Boolean> type.
14 The value is stored as an Integer.
24 #include "lua_private.h"
41 Initializes the Boolean with a default value of C<false>.
47 PMC_int_val(SELF) = 0;
52 =item C<PMC new_from_string(STRING *rep)>
54 Class method to construct an Boolean from the string representation C<rep>.
59 PMC* new_from_string(STRING *rep, INTVAL flags) {
61 INTVAL type = PMC_type(SELF);
62 if (flags & PObj_constant_FLAG)
63 res = constant_pmc_new(INTERP, type);
65 res = pmc_new(INTERP, type);
66 PMC_int_val(res) = (string_to_int(INTERP, rep) != 0);
72 =item C<STRING* name()>
74 Return the string "boolean".
80 return const_string(INTERP, "boolean");
87 Creates and returns a clone of the scalar.
93 PMC *dest = pmc_new(INTERP, PMC_type(SELF));
94 STRUCT_COPY(&PMC_union(dest), &PMC_union(SELF));
100 =item C<INTVAL get_integer()>
102 Returns the integer value of the Boolean.
107 INTVAL get_integer() {
108 return PMC_int_val(SELF);
113 =item C<STRING* get_string()>
115 Return the string "true" or "false".
120 STRING* get_string() {
121 if (PMC_int_val(SELF))
122 return const_string(INTERP, "true");
124 return const_string(INTERP, "false");
130 =item C<INTVAL get_bool()>
132 Returns the boolean value of the Boolean.
138 return PMC_int_val(SELF) ? 1 : 0;
143 =item C<void set_integer_native(INTVAL value)>
145 =item C<void set_bool(INTVAL value)>
150 void set_integer_native(INTVAL value) {
151 PMC_int_val(SELF) = (value != 0);
154 void set_bool(INTVAL value) {
155 PMC_int_val(SELF) = (value != 0);
160 =item C<void set_pmc(PMC *value)>
162 Sets the value of the boolean to the value in C<*value>.
167 void set_pmc(PMC *value) {
168 PMC_int_val(SELF) = VTABLE_get_bool(INTERP, value);
173 =item C<void freeze(visit_info *info)>
175 Used to archive the boolean.
180 void freeze(visit_info *info) {
181 IMAGE_IO *io = info->image_io;
183 VTABLE_push_integer(INTERP, io, PMC_int_val(SELF));
188 =item C<void thaw(visit_info *info)>
190 Used to unarchive the boolean.
195 void thaw(visit_info *info) {
196 IMAGE_IO *io = info->image_io;
198 if (info->extra_flags == EXTRA_IS_NULL)
199 PMC_int_val(SELF) = VTABLE_shift_integer(INTERP, io);
206 =head2 non-Vtable Methods
210 =item C<INTVAL is_equal(PMC *value)>
215 INTVAL is_equal(PMC *value) {
217 return (INTVAL)(PMC_int_val(SELF) == PMC_int_val(value));
228 =head2 Specific Methods
232 =item C<PMC* rawequal(PMC *value)>
237 METHOD PMC* rawequal(PMC *value) {
238 PMC *retval = pmc_new(INTERP, dynpmc_LuaBoolean);
240 if (PMC_type(SELF) == PMC_type(value)
241 && PMC_int_val(SELF) == VTABLE_get_integer(INTERP, value))
242 VTABLE_set_integer_native(INTERP, retval, 1);
244 VTABLE_set_integer_native(INTERP, retval, 0);
268 * c-file-style: "parrot"
270 * vim: expandtab shiftwidth=4: