[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Tools for high level game AI
- From: Steven Johnson <temujin98007@...>
- Date: Sun, 7 Sep 2008 06:46:24 -0700 (PDT)
Hi.
> I have read that chapters. thanks for pointing them out.
> After some code testing (in scheme) I have two question (both about lua):
> - When I tried to use your two files I got error:
> /usr/share/lua/5.1/Coroutine.lua:6: attempt to index global 'callops' (a nil \
> value)
> Where this module callops can be found?
Sorry about that. That was my quick comment about utility functions :). These
are all basically just "saves typing" / "saves function / table creation" functions.
It ought to be fine to use the following:
local type = type
local function IsCallable (object)
return type(object) == "function"
end
or in C as:
int AuxIsCallable (lua_State * L, int index)
{
if (lua_isfunction(L, index)) return 1;
if (luaL_getmetafield(L, index, "__call") == 0) return 0; // __call
lua_pop(L, 1);
return 1;
}
static int IsCallable (lua_State * L)
{
lua_pushboolean(L, AuxIsCallable(L, 1)); // bIsCallable
return 1;
}
and
local function NOP () end
You can put
setmetatable({}, { __mode = MODE }
in for the table_ex.Weak(MODE) calls, with appropriate MODE values.
(In the other utilties there's also GetTimeLapseFunc, which can just
supply any function that returns the time lapse for the current frame.
It was designed with a companion SetTimeLapseFunc to allow for
custom time functions in Wait.
I plan to eventually make available a lot of this library stuff with
dependencies intact, which (hopefully) would alleviate situations like this.)
> - Can you show me how to modify your lua parlol example by supplying
> function that will return all possible combinations of two numbers?
> I have been trying to do it in scheme but with no success. I could though
> get them one by one by manually typing (fail).
As I hinted, it's not very mature yet. After the first non-fail the Choose
returns and the internal coroutine is lost. Maybe I'll add a ChooseMulti or
ChooseAll variant function with an accumulator table as argument or return
value, where in place of this line in coroutineops.lua
return choice
it would have
choices[#choices + 1] = choice
You would also need to pass a fail function, which could just be a no-op,
to the outer Choose so that it terminates gracefully (otherwise, in the best
case, it'll error on Reset).
Hope that helps / makes sense. If not, I blame trying to reason about this
without coffee. :D I'll mess around with it tomorrow morning and post an
example if it works and you haven't already done it.
- Steve