From c8e76b5048b3457e1ed669a1413adff5175a2965 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 9 Oct 2006 07:30:48 +0000 Subject: [PATCH] add Def{} helper. (This uses the debug API. This particular use seems OK, but maybe should be abstracted.) --- stepmania/Themes/default/Scripts/00 init.lua | 9 ++++++ stepmania/Themes/default/Scripts/Actor.lua | 32 ++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/stepmania/Themes/default/Scripts/00 init.lua b/stepmania/Themes/default/Scripts/00 init.lua index 8f4650d53d..d3aa5cda48 100644 --- a/stepmania/Themes/default/Scripts/00 init.lua +++ b/stepmania/Themes/default/Scripts/00 init.lua @@ -10,6 +10,15 @@ PLAYER_1 = "PlayerNumber_P1" PLAYER_2 = "PlayerNumber_P2" 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 -- All rights reserved. -- diff --git a/stepmania/Themes/default/Scripts/Actor.lua b/stepmania/Themes/default/Scripts/Actor.lua index 7326daa5a3..978746774a 100644 --- a/stepmania/Themes/default/Scripts/Actor.lua +++ b/stepmania/Themes/default/Scripts/Actor.lua @@ -92,6 +92,38 @@ function Actor:scale_or_crop_background() 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 -- All rights reserved. --