add Def{} helper.
(This uses the debug API. This particular use seems OK, but maybe should be abstracted.)
This commit is contained in:
@@ -10,6 +10,15 @@ PLAYER_1 = "PlayerNumber_P1"
|
|||||||
PLAYER_2 = "PlayerNumber_P2"
|
PLAYER_2 = "PlayerNumber_P2"
|
||||||
NUM_PLAYERS = #PlayerNumber
|
NUM_PLAYERS = #PlayerNumber
|
||||||
|
|
||||||
|
function string:find_last( text )
|
||||||
|
local LastPos = 0;
|
||||||
|
while true do
|
||||||
|
local p = string.find( self, text, LastPos+1, true );
|
||||||
|
if not p then return LastPos end
|
||||||
|
LastPos = p;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- (c) 2006 Glenn Maynard
|
-- (c) 2006 Glenn Maynard
|
||||||
-- All rights reserved.
|
-- All rights reserved.
|
||||||
--
|
--
|
||||||
|
|||||||
@@ -92,6 +92,38 @@ function Actor:scale_or_crop_background()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Def = {}
|
||||||
|
setmetatable( Def, {
|
||||||
|
__index = function(self, Type)
|
||||||
|
-- t is an actor definition table. name is the type
|
||||||
|
-- given to Def. Fill in standard fields.
|
||||||
|
return function(t)
|
||||||
|
if not t.Type then
|
||||||
|
t.Type = Type;
|
||||||
|
end
|
||||||
|
|
||||||
|
local info = debug.getinfo(2,"Sl");
|
||||||
|
|
||||||
|
-- Source file of caller:
|
||||||
|
local Source = info.source;
|
||||||
|
t._Source = Source;
|
||||||
|
|
||||||
|
if Path:sub( 1, 1 ) == "@" then
|
||||||
|
local Path = Source:sub( 2 );
|
||||||
|
|
||||||
|
-- Directory of caller, for relative paths:
|
||||||
|
local pos = Path:find_last( '/' );
|
||||||
|
t._Dir = string.sub( Path, 1, pos );
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Line number of caller:
|
||||||
|
t._Line = info.currentline;
|
||||||
|
|
||||||
|
return t;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
});
|
||||||
|
|
||||||
-- (c) 2006 Glenn Maynard
|
-- (c) 2006 Glenn Maynard
|
||||||
-- All rights reserved.
|
-- All rights reserved.
|
||||||
--
|
--
|
||||||
|
|||||||
Reference in New Issue
Block a user