Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This converts a Source Engine .VMF Hammer File into a readable table in Lua.
- -- Example VMF File String.
- -- http://pastebin.com/ib6RtFDk
- -- This function just parses the file (as a string) into a table.
- -- If there's a better version for this stuff online, please for the love of god let me know lol.
- function ConvertVMF(file)
- local fileConv = {}
- local current = 0
- local stack = 0
- local stackRefs = {[0] = fileConv}
- local lines = {}
- for line in string.gmatch(file,"[^\r\n]+") do
- table.insert(lines,line)
- end
- while current <= #lines do
- current = current + 1
- local line = lines[current]
- if line then
- local tabs = 0
- for i in string.gmatch(line,"\t") do
- tabs = tabs + 1
- end
- local k,v = string.match(line,'%"(.-)%" %"(.-)%"')
- if k and v then
- stackRefs[stack][k] = tonumber(v) or v
- elseif string.find(line,"{") then
- local previousLine = lines[current-1]
- local nextLine = lines[current+1]
- if previousLine and nextLine then
- local f,l = string.find(previousLine,string.rep("\t",tabs))
- if f and l then
- local id = string.match(nextLine,'"id" %"(.-)%"')
- local key = string.sub(previousLine,l+1)
- if id then
- current = current + 1
- key = key..id
- end
- local loc = stackRefs[stack]
- local self = {}
- stack = stack + 1
- stackRefs[stack] = self
- loc[key] = self
- end
- end
- elseif string.find(line,"}") then
- stackRefs[stack] = nil
- stack = stack - 1
- end
- end
- end
- return fileConv
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement