brettviren / moo

ruminants on module oriented programming
GNU General Public License v3.0
4 stars 4 forks source link

Default value for boolean #20

Closed strilov closed 3 years ago

strilov commented 3 years ago

Hello,

The following schema jsonnet,

local moo = import "moo.jsonnet";
// A schema builder in the given path (namespace)
local ns = "test";
local s = moo.oschema.schema(ns);
local test = {
    bool_data: s.boolean("BoolData", doc="A bool"),
    a_record: s.record("ARecord", 
    [
        s.field("a_field", self.bool_data, false,
                doc="A test field"),
    ], 
    doc="Test record"),
};
// Output a topologically sorted array.
moo.oschema.sort_select(test, ns)

generates the following hpp file:

#ifndef TEST_STRUCTS_HPP
#define TEST_STRUCTS_HPP
#include <cstdint>
namespace test {
    // @brief A bool
    using BoolData = bool;
    // @brief Test record
    struct ARecord {
        // @brief A test field
        BoolData a_field = False;
    };
} // namespace test
#endif // TEST_STRUCTS_HPP

where BoolData a_field = False; is not valid C++.

Do you know if this is an issue with moo?

Regards, Stoyan

brettviren commented 3 years ago

Hi @strilov

Thanks, yes, this looks to be a gap in C++ support in the templates. The Python "spelling" of false is leaking through and not getting translated to a C++ spelling. I'll fix it.