LS2Module:Building an Enum
From ismods.com: dedicated to promoting white hat, EULA-compliant Inner Space and LavishScript mods
An Enum is a special Type which inherits from System.Enum.
Designing an Enum is considerably easier than other kinds of Types.
Resolve System.Enum
- Use ILS2StandardEnvironment::ResolveType to grab a reference to System.Enum
LavishScript2::LS2SmartRef<LavishScript2::ILS2CodeBoxType> pSystemEnum; g_pLS2Environment->ResolveType(L"System.Enum",pSystemEnum);
Register your Type
- Use ILS2StandardEnvironment::RegisterType to register your new Type and inherit from System.Enum
if (!g_pLS2Environment->RegisterType(L"SQLite.DataTypeEnum",pSystemEnum,&g_pLS2_SQLiteDataTypeEnum)) { return false; }
Register Enum Values
For each Value to add to your Enum, you will need to:
- Set up a LS2CodeBoxValue_Enum via ILS2StandardEnvironment::NewEnum with its numeric value, e.g. g_pLS2Environment->NewEnum(1,pSystemEnum,pEnumValue)
- Register a Static Field with the value's Name and, for the C# Declaration, its initializer in the form Name=Value, e.g. g_pLS2_SQLiteDataTypeEnum->RegisterStaticField(L"Integer",L"",L"Integer=1",pEnumValue,0)
- A fully-implemented example with 5 values
{ LavishScript2::LS2SmartRef<LavishScript2::LS2CodeBoxValue_Enum> pEnumValue; g_pLS2Environment->NewEnum(1,pSystemEnum,pEnumValue); if (!g_pLS2_SQLiteDataTypeEnum->RegisterStaticField(L"Integer",L"",L"Integer=1",pEnumValue,0)) { return false; } g_pLS2Environment->NewEnum(2,pSystemEnum,pEnumValue); g_pLS2_SQLiteDataTypeEnum->RegisterStaticField(L"Float",L"",L"Float=2",pEnumValue,0); g_pLS2Environment->NewEnum(3,pSystemEnum,pEnumValue); g_pLS2_SQLiteDataTypeEnum->RegisterStaticField(L"Text",L"",L"Text=3",pEnumValue,0); g_pLS2Environment->NewEnum(4,pSystemEnum,pEnumValue); g_pLS2_SQLiteDataTypeEnum->RegisterStaticField(L"Blob",L"",L"Blob=4",pEnumValue,0); g_pLS2Environment->NewEnum(5,pSystemEnum,pEnumValue); g_pLS2_SQLiteDataTypeEnum->RegisterStaticField(L"Null",L"",L"Null=5",pEnumValue,0); }