Created
September 2, 2019 10:33
-
-
Save neilpopham/baae794e22251c83afe7520c621246d8 to your computer and use it in GitHub Desktop.
PHP script to parse a TIC 80 lua file and replace requires() with the contents of the files required. Use before saving as .tic.
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
<?php | |
$strRoot = "C:\\Users\\Neil\\AppData\\Roaming\\com.nesbox.tic\\TIC-80\\"; | |
$strMain = file_get_contents($argv[1]); | |
if (preg_match_all('/^require \"(.+?)\"$/m', $strMain, $arrMatches)) { | |
foreach ($arrMatches[1] as $i => $strFile) { | |
$strPath = $strRoot . '\\' . str_replace(["carts/", "\/"], ["", "\\"], $strFile) . ".lua"; | |
$strRequire = file_get_contents($strPath); | |
$strRequire = trim($strRequire) . "\n"; | |
$strRequire = "-- {$strFile}.lua\n\n" . $strRequire; | |
$strMain = str_replace( | |
$arrMatches[0][$i], | |
$strRequire, | |
$strMain | |
); | |
} | |
file_put_contents(str_replace(".lua", ".merged.lua", $argv[1]), $strMain); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To clarify: