User-script dofile and loadfile check for "clua" anywhere in the file name and refuse to load the file in that case; only core Crawl code can load Lua files from clua/*.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1622 c06c8d41-db1a-0410-9941-cceddc491573
HNXKX6ZDQJV33E7UKZOLBYWJMRZ4QLEMXVXJZNRCTOIG2KVRTIEAC
UB73UGG2GEG6AL4T76UILFLTELH4Z5WN54UROLJD6RDR3JG77CXAC
AVSMB4Y6F6ZMMNNPOAQQZ34OWC6N5JOURTEWFTUKDWMIIMLWWJUAC
RC6L3CIBLJEH4GWRFD7UQNGI6PZT74FRUVOYHSAN2XCC74NZUASQC
RPOZZWKG5GLPHVZZ7ZKMKS64ZMV2LDCQSARBJFJ6FZOTOKCQO7FAC
4EWXDZSMYTEINQRUL4OHRUZVWMKCWEPYVJVGENQPBWUYU37SP63QC
ZGM2JSUXIFZJOHJSZA2RT6RFP6AVY3UVSIXFFIUDAMWHT3ONNHGQC
3A537UMVZSYIFVKVO3SVK5JRSRLDN3YJKK3RKELHR2D4U6CMKM4QC
QXQE7C5XDYNF4JSHGDAVMS7HYLOC6YEZFOVFJ3RD7RB6U4AJSFIQC
IWFPY33RKYC6R54OBK5ZEMVSFBPYYYILOOCAA3NY6MDSNE73JP3AC
SDLKLUNFGVKDS55DDJZCBAVIB7NL3RRYPTACAY65SCUQKV6APFSAC
K2CS6TCX2NDVL2ASEHGP4J4K4IJ6FP3ANNKTSIWVG43HPYSBX6ZQC
SH6NU4H5TG4O7CRXRHZ7MDHABZLWWXQ77NJDBHI7KCVHXHQYK46QC
NXVPOFYKJFWQWKVPQUMWH2Y2KJEZX44BUOBFJ4JD4KFGPEGYHG4QC
YE7M665QKDGI7Y5WMERCWJNDZ4FUZ6GRUCK4E6GZH4SWCUM6RWLAC
------------------------------------------------------------------
-- macro.lua:
-- Crawl macro framework for Lua.
--
-- Macros are called as Lua coroutines. If the macro yields false, the
-- coroutine is discarded (assuming an error). If the macro yields
-- true, Crawl will start a macro delay for the macro and call the
-- coroutine again next turn. If the macro just returns, the coroutine
-- is assumed to be done.
--
-- Why coroutines: Macros may need to perform actions that take
-- multiple turns, which requires control to return to Crawl to
-- perform world updates between actions. Coroutines are the simplest
-- way to pass control back and forth without losing the macro's
-- state.
------------------------------------------------------------------
function c_macro(fn)
if fn == nil then
if c_macro_coroutine ~= nil then
local coret, mret
coret, mret = coroutine.resume(c_macro_coroutine)
if not coret or not mret then
c_macro_coroutine = nil
c_macro_name = nil
end
if not coret and mret then
error(mret)
end
return (coret and mret)
end
return false
end
if _G[fn] == nil or type(_G[fn]) ~= 'function' then
return false
end
c_macro_name = fn
c_macro_coroutine = coroutine.create(_G[fn])
return c_macro()
end
static const char *c_macro =
"function c_macro(fn)"
" if fn == nil then"
" if c_macro_coroutine ~= nil then"
" local coret, mret"
" coret, mret = coroutine.resume(c_macro_coroutine)"
" if not coret or not mret then"
" c_macro_coroutine = nil"
" c_macro_name = nil"
" end"
" if not coret and mret then"
" error(mret)"
" end"
" return (coret and mret)"
" end"
" return false"
" end"
" if _G[fn] == nil or type(_G[fn]) ~= 'function' then"
" return false"
" end"
" c_macro_name = fn"
" c_macro_coroutine = coroutine.create(_G[fn]) "
" return c_macro() "
"end";
execstring(c_macro, "base");
execfile("clua/macro.lua", true);