Commit Graph

114 Commits

Author SHA1 Message Date
Glenn Maynard 37932a8cc8 add FOREACH_LUATABLEI 2007-02-12 03:59:18 +00:00
Glenn Maynard f45875adc7 add helpers 2007-02-04 08:03:47 +00:00
Glenn Maynard 510f900d28 lua.RunWithThreadVariables: Lua interface to LuaThreadVariables 2007-02-03 10:20:15 +00:00
Glenn Maynard c80639acbd remove LuaFunctionList 2007-01-14 00:20:16 +00:00
Glenn Maynard e1dd488e32 use REGISTER_WITH_LUA_FUNCTION instead of a separate registration mechanism 2007-01-14 00:16:31 +00:00
Steve Checkoway 7f7b0ecb5d Don't create a new class just to register a function with lua. 2006-11-19 00:53:43 +00:00
Glenn Maynard dab10ec033 const 2006-11-02 05:47:32 +00:00
Glenn Maynard 854b259ef1 Replace actor parameters with thread variables.
This is to provide parameters to loading Actor definitions, in a way that
does not need to be explicitly propagated to nested definitions; I want
loading a sub-definition to remain a simple function call with no mandatory
(prescribed) parameters.  This provides a general context to pass information
to Lua about what it's loading, such as LoadingScreen.

These are scoped to the running thread, unlike global variables.  This prevents
possible threading problems.

All thread variables are scoped: set a variable, do something, unset it; when
finished, all thread variables are unset.

These are no longer available after load.  By design, to use these later,
use upvalues:

local color = lua.GetVar("color");
return Def.Quad {
    OnCommand=cmd(diffuse,color);
}
2006-11-02 04:23:19 +00:00
Glenn Maynard 708fa0166e move lock into pImpl 2006-10-31 01:23:25 +00:00
Glenn Maynard f9496f96d9 remove another specialized "parse and evaluate string" 2006-10-29 20:52:25 +00:00
Glenn Maynard ff2b6f697c PrepareExpression only used in one place and simple; merge down 2006-10-29 20:48:02 +00:00
Glenn Maynard e246824ce3 remove ugly RunAtExpressionS 2006-10-23 20:40:32 +00:00
Glenn Maynard e5c216c8f0 remove unused (way too many little custom ways of loading Lua scripts) 2006-10-23 20:25:20 +00:00
Steve Checkoway bffe668d00 Real unique names now. 2006-10-16 04:52:12 +00:00
Glenn Maynard 2cede5a421 for cases where we take a number as a boolean, accept a boolean
false as false (to transition away from numbers)
2006-10-15 08:17:35 +00:00
Steve Checkoway 335227c095 Nothing is pushed when lua_next() returns 0. 2006-10-15 07:39:16 +00:00
Steve Checkoway 943ba7e0fa FOREACH_LUATABLE simplifies iterating over all key-value pairs in the lua table at index. One difference with calling lua_next() is that the key is duplicated and pushed onto the stack above the value. At the beginning of the loop body the stack looks like:
-1 key
-2 value
-3 key
...
The top key and value can be removed or modified as required. The key at -3 should not be touched since it is required for the next iteration through the loop.

Stack management is simplified. Anything left on the stack above the key will be popped. After the loop terminates normally, the stack will be as it was before the loop was entered (no nil values to clean up).
2006-10-15 03:15:32 +00:00
Glenn Maynard c8a8572a21 Allow yielding the Lua engine. This fixes a long-standing limitation
with Lua bindings: they couldn't read from disk, or render, or do anything
else potentially time-consuming, because that would hold the Lua lock,
preventing other threads from using it.
2006-10-15 01:58:36 +00:00
Glenn Maynard 10b96b08b8 LuaHelpers::DeepCopy 2006-10-15 01:40:11 +00:00
Glenn Maynard 7282c5668b moved 2006-10-15 01:16:13 +00:00
Glenn Maynard 71af20fdf8 allow passing params to RunScript 2006-10-15 01:14:32 +00:00
Glenn Maynard 3dc13b568a LuaManager::L -> m_pLuaMain 2006-10-14 20:49:35 +00:00
Glenn Maynard 89b435ef51 LuaManager::GetLuaInformation -> LuaHelpers::GetLuaInformation 2006-10-14 20:35:32 +00:00
Glenn Maynard d7776aba60 evaluate enums directly 2006-10-09 01:34:16 +00:00
Glenn Maynard 6322ded0dc move command parsing into LuaHelpers. It's not Actor-specific other
than a few compatibility hacks.
2006-10-08 22:24:15 +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 c80451fe46 fix stack imbalance 2006-10-06 00:46:06 +00:00
Glenn Maynard 47a1ab39bd add LuaHelpers::PushValueFunc 2006-10-05 19:57:07 +00:00
Glenn Maynard dcc1cb0d86 merge LuaFunctions.h into LuaManager.h 2006-09-29 09:31:41 +00:00
Steve Checkoway c89f3f9335 Don't bother getting the max. Just go until we find a nil element, that's all the # operator is going to do. 2006-09-26 09:35:15 +00:00
Glenn Maynard f567a0fd28 cleanup arg order 2006-09-26 08:54:54 +00:00
Steve Checkoway 9914f50ade Safe macros. (Probably only needed if the type of argument is not known at compile time and accessed with something other than a constant.) 2006-09-26 05:50:40 +00:00
Steve Checkoway 6fe6baa241 Unused. The purpose of this connivence function as stated in the comments (which isn't quite what it did) is exactly what RunExpression does. 2006-09-26 05:35:24 +00:00
Glenn Maynard 923f0f7346 inline 2006-09-26 01:36:31 +00:00
Glenn Maynard 78c8e11290 add LuaHelpers::AbsIndex 2006-09-26 01:28:10 +00:00
Glenn Maynard 1554e02329 always use our headers 2006-09-25 07:36:14 +00:00
Glenn Maynard de88aa1d94 remove unused 2006-09-25 06:52:46 +00:00
Glenn Maynard 0d05ebd9b5 always leave iReturnValues on the stack, even on error, so error handling can just log the error and continue as if nil was actually returned 2006-09-23 02:44:35 +00:00
Glenn Maynard 59e1be60e6 simplify RunExpressionX. Don't check for function returns;
it's confusing to do it inconsistently.  Now, this code
path looks like the theme metric one.
2006-09-23 02:11:54 +00:00
Glenn Maynard 13f33de79a allow passing sName for expressions 2006-09-23 02:09:58 +00:00
Glenn Maynard 494c3cd485 LuaHelpers::RunExpression 2006-09-22 18:53:39 +00:00
Glenn Maynard 709a790f1c change arg order 2006-09-22 08:48:49 +00:00
Glenn Maynard f29762c59e change arg order 2006-09-22 08:38:30 +00:00
Glenn Maynard 557563e81d cleanup 2006-09-22 08:33:20 +00:00
Steve Checkoway 6ad2454400 Cleanup. 2006-09-21 07:25:38 +00:00
Steve Checkoway 175ae8cac4 I ended up not using this. 2006-09-21 07:19:13 +00:00
Steve Checkoway 93a5184cfd Simplify. Now FromStack() is unused except for Pop(). 2006-09-21 07:12:49 +00:00
Steve Checkoway d7e64dc979 Simplify. PushStack was only calling Push and possibly generating a function for each enumerated type which in the end only called Push. Rename PopStack -> Pop to be symmetric with Push. 2006-09-21 07:06:18 +00:00
Steve Checkoway 064f147f84 Unneeded. 2006-09-21 06:52:39 +00:00
Glenn Maynard 1749779ca8 merge ResetState into ctor 2006-09-20 23:47:08 +00:00