Commit Graph
78 Commits
Author SHA1 Message Date
Glenn Maynard a1611de0c4 handle Invalid enum values through FromStack 2007-01-15 04:14:19 +00:00
Steve Checkoway fbd0863d56 Unused. 2006-10-15 00:09:59 +00:00
Steve Checkoway e87789da7c Rename XToString2 to XToString. 2006-10-15 00:09:18 +00:00
Glenn Maynard ed6141c48f By default, don't return Invalid values from Enum::Check. It's the exception
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.)
2006-10-11 05:18:12 +00:00
Glenn Maynard 5c1ffb5c6a simplify 2006-10-08 04:29:09 +00:00
Glenn Maynard 617e8b5335 FOREACH_ENUM2 -> FOREACH_ENUM 2006-10-07 08:56:58 +00:00
Glenn Maynard 30fd6d77b4 maybe workaround g++ 3.3 weirdness 2006-10-07 08:56:12 +00:00
Glenn Maynard 82f51bc3d4 more generic type-punning helper 2006-10-07 08:17:15 +00:00
Glenn Maynard d882f21348 make ToString and FromString templates 2006-10-07 06:21:39 +00:00
Glenn Maynard 4e83c166b9 simplify 2006-10-07 04:40:14 +00:00
Glenn Maynard 4b30d3552d A bizarre C++ wart wants us to declare FromStack overloads
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).
2006-10-07 01:22:28 +00:00
Glenn Maynard eeedbade1a don't set TypeIndex. Use type:Reverse(). 2006-10-05 23:15:57 +00:00
Glenn Maynard 3407b92ede bind the enum table to a methods table 2006-10-05 23:08:42 +00:00
Steve Checkoway 03ed75018f Fix compile for apple's g++ 4.0.1. 2006-10-05 10:32:57 +00:00
Steve Checkoway d2b9ea130d Separate declaration from definition. This way, if LuaXType( Foo ) is used without a preceding LuaDeclareType( Foo ) the compiler will complain. 2006-10-02 01:31:24 +00:00
Steve Checkoway 78d3e04936 For some reason, explicitly instantiating struct EnumTraits<X> isn't enough. When defining the static members, it needs template<> as well. 2006-10-02 00:49:11 +00:00
Glenn Maynard cd8f1fc1c6 "I made this"
lua_replace -> lua_remove
2006-09-30 21:55:31 +00:00
Glenn Maynard 6409c606ec 'EnumTraits<T>' : type name first seen using 'struct' now seen using 'class' 2006-09-30 05:07:07 +00:00
Steve Checkoway 0acebabd01 We're instantiating the class, not the class members. 2006-09-30 04:03:42 +00:00
Glenn Maynard 84163cb7af "too few template-parameter-lists" 2006-09-30 03:18:15 +00:00
Steve Checkoway e5441dfec7 Lua header. 2006-09-28 06:28:46 +00:00
Glenn Maynard 982228b7e6 bind StepsType 2006-09-27 06:09:52 +00:00
Glenn Maynard ed65f03048 XToString2 2006-09-27 05:48:46 +00:00
Glenn Maynard e183a023d5 unused 2006-09-27 05:47:18 +00:00
Glenn Maynard b1ae2b9288 for ARRAYLEN 2006-09-27 05:45:54 +00:00
Glenn Maynard 07059f85e3 fix FOREACH_UsedGrade
FOREACH_ENUM2 -> FOREACH_ENUM
2006-09-27 05:27:28 +00:00
Glenn Maynard be7cf3d347 FOREACH_ENUM2 2006-09-27 05:25:22 +00:00
Glenn Maynard 73f9ccd0d8 always use NUM_##e 2006-09-27 04:46:18 +00:00
Glenn Maynard 755e18138e simplify 2006-09-27 04:25:22 +00:00
Glenn Maynard 2baddd84fc COMPILE_ASSERT XToString table sizes
pull out common XToString code
simplify XToString
2006-09-27 04:19:47 +00:00
Glenn Maynard 7305d0d70a don't use CNT parameter 2006-09-26 21:38:30 +00:00
Glenn Maynard f567a0fd28 cleanup arg order 2006-09-26 08:54:54 +00:00
Glenn Maynard 600fdfea63 simplify LuaXType 2006-09-26 07:13:54 +00:00
Glenn Maynard 0709d5ee4d remove LuaXType2 2006-09-26 06:48:53 +00:00
Glenn Maynard a0373a0add cleanup 2006-09-26 06:36:08 +00:00
Glenn Maynard 687e006cdf remove unused 2006-09-26 05:17:29 +00:00
Glenn Maynard 64dec0bb42 fix StringToEnum 2006-09-26 05:03:55 +00:00
Glenn Maynard 9756e3287f remove old macro, transition 2006-09-26 04:15:39 +00:00
Steve Checkoway 68dd073282 Pasting "PlayMode_" and "Index" does not make a valid preprocessing token. 2006-09-26 04:06:03 +00:00
Glenn Maynard d2968acd5e expose the index table; helpful for the few places we need to order enums 2006-09-26 03:58:30 +00:00
Glenn Maynard 27fda541dc split EnumTraits (static variables associated with an enum type)
and Enum (functions)

define Push for enum types
2006-09-26 03:05:08 +00:00
Glenn Maynard edfaafe617 remove "NUM_CourseTypes"; use #CourseTypes 2006-09-26 01:55:37 +00:00
Glenn Maynard 3d79319c04 Register Lua enum types as strings, not numbers.
- 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.
2006-09-26 01:41:40 +00:00
Steve Checkoway a4aa69b148 Remove ThemeMetricEnum. Since all metrics are evaluated as lua, use lua integer constants. 2006-09-23 07:21:26 +00:00
Glenn Maynard e206261b80 ARRAYSIZE -> ARRAYLEN 2006-09-13 03:11:38 +00:00
Steve Checkoway 0099258f5f Cleanup. 2006-09-01 02:09:49 +00:00
Steve Checkoway a07e194cf1 Revert. Fixes Linux build. 2006-07-18 05:51:37 +00:00
Jason Felds 366c3440d4 Fix VC8 macro redef warning. (more to come) 2006-07-18 03:56:37 +00:00
Thad Ward 2684d8fa63 revert. VC6 doesn't have auto_ptr::reset() 2006-07-14 07:49:59 +00:00
Steve Checkoway 6f27069ac0 Simplify. 2006-07-03 06:45:14 +00:00