that Invalid has a meaning for an API call; most do not. As it was, every
function that used Enum::Check should have been checking for invalid
return values; this way, the check can be omitted.
(This applies to FromString, Pop and FromStack, too; I havn't decided
whether I want to propagate this into those.)
before the ThemeMetric templates that use them. That's broken
and unreasonable, so change this around a bit and make FromStack
(and Push) templates.
Push() takes a bit of a trick. Some Push overloads push the
actual value: scalars (int, float), RageColor (pushes a table).
Others--most of them--push a reference to a C++ object. We
want the scalars to have a reference parameter type, so we
don't make extra copies of things like RageColor when we push
them. We need to pass C++ objects by pointer (we need to
push the actual object's pointer, not a pointer to a copy).
Further, pushing a scalar is a const operation, but pushing
a reference to an object is not.
To do both with the same template, we handle objects with
this slightly odd template:
template<> void LuaHelpers::Push<T*>( lua_State *L, T *const &pObject );
The actual overload (T) is eg. "Actor*"; this fits within the
general prototype, "Push(lua_State *L, const T &object)", giving
us a const reference to a (non-const) pointer to Actor, and we're
conceptually pushing the pointer.
The net effect of this is that 1: what was before compile errors
now becomes link time errors, but 2: these specializations
don't have to be in the headers (except for new ones for
Preference and BroadcastOnChange).
- Even though these strings are in the context of the table, we still prefix them
with the enum name ("UnlockRequirement_ArcadePoints", not "ArcadePoints"). The typical
use is as a simple string (obj:Call("Type")), not as an index into the table, and
this makes the type clear and easy to search for in that case.
- no "NUM_UnlockRequirement"; use #UnlockRequirement.
- no UnlockRequirement_Invalid; use nil
- Enum<X>::Check always returns a valid X; no additional error checking is
needed and Lua code can no longer introduce invalid enum values into C
- This does not support enum types with holes; neither does FOREACH.
- This is typesafe. If you give "GAME_CONTROLLER_1" to a function expecting an
UnlockRequirement, we can detect the error and show a meaningful error message.
- Lua strings are always merged, and comparisons are as cheap as integers, so
this isn't slow (and may be faster).
- Can iterate: for i,j in ipairs(UnlockEntry) do func(j) end
(This is a bit clumsy; probably want a foreach() iterator that doesn't return i)
- ThemeMetric<UnlockRequirement> just works.