Created
March 12, 2016 13:37
-
-
Save MikuAuahDark/2926368c73b24aead1eb to your computer and use it in GitHub Desktop.
Makefile-compatible Lua script/Lua-compatible Makefile/Lua script in Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__unused = #string -- This is a Makefile which is also executable by Lua | |
__unused = #string --[[ | |
#Your Makefile script starts here | |
default: | |
@echo "Hello!" | |
#Your Makefile script ends here | |
ifeq (0,1) | |
__unused = #string ]]-- | |
-- Your lua script starts here | |
print("Hello!") | |
-- Your lua script ends here | |
__unused = #string --[[ | |
endif | |
__unused = #string ]]-- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Explanation
First line,
__unused = #string -- This is a Makefile which is also executable by Lua
is both valid in Lua and Makefile. It will set global variable__unused
to 0 (because#string
is 0) in Lua, while it will set__unused
to#string -- This is a Makefile which is also executable by Lua
in MakefileSecond line,
__unused
variable will be set to#string --[[
in Makefile. While in Lua, it will set__unused
global variable AGAIN to 0 and start block of comment (--[[
). After that line, all makefile script will be valid, as long as it doesn't have character]]
in the Makefile string.Line 8 will absolutely false, so Makefile won't see it and we can put anything in it (source) as long as it is not one of Makefile keywords and/or symbols.
Line 9 will actually closes the comment block in Lua (
]]--
) and below that line, you can write your Lua script. Just make sure that it doesn't contain any of Makefile keywords and/or symbols or Makefile will complain about it.When your script ends, line 14 will open block of comment again (
--[[
) and line 15, closes theifeq
statement for Makefile in line 8. To prevent Lua complaining aboutunfinished long comment
,__unused
will be set again to#string ]]--
and closes the Lua comment block because]]--
.