webmcp
diff framework/env/slot/use_temporary.lua @ 0:9fdfb27f8e67
Version 1.0.0
author | jbe/bsw |
---|---|
date | Sun Oct 25 12:00:00 2009 +0100 (2009-10-25) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/framework/env/slot/use_temporary.lua Sun Oct 25 12:00:00 2009 +0100 1.3 @@ -0,0 +1,22 @@ 1.4 +--[[-- 1.5 +slot_content = 1.6 +slot.use_temporary( 1.7 + function() 1.8 + ... 1.9 + end 1.10 +) 1.11 + 1.12 +This function creates a temporary slot and executes code in a way that slot.put(...) and other functions will write into the temporary slot. Afterwards the contents of the temporary slot are returned as a single string. 1.13 + 1.14 +--]]-- 1.15 + 1.16 +function slot.use_temporary(block) 1.17 + local old_slot = slot._active_slot 1.18 + local temp_slot_reference = {} -- just a unique reference 1.19 + slot._active_slot = temp_slot_reference 1.20 + block() 1.21 + slot._active_slot = old_slot 1.22 + local result = slot.get_content(temp_slot_reference) 1.23 + slot.reset(temp_slot_reference) 1.24 + return result 1.25 +end