Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fragments = {}
- function load_fragment(location)
- location = location .. ".lua"
- local file = io.open(location, "r")
- if (file) then
- local frag_source = file:read("*all")
- fragments[location] = frag_source
- file:close()
- return frag_source
- end
- end
- function get_fragment(location)
- if (fragments[location]) then
- return fragments[location]
- else
- return load_fragment(location)
- end
- end
- function load_source(location)
- location = location .. ".lua"
- local file, err = io.open(location, "r")
- if (file) then
- local source = file:read("*all")
- for statement, fragment_location in source:gmatch("(--@include ([^\n]+))") do
- local fragment = get_fragment(fragment_location) or "--FRAGMENT '" .. fragment_location .. "' NOT FOUND"
- source = source:gsub(statement, fragment)
- end
- return source
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement