Thanks guys! I managed to get it working perfectly
Forboding Angel wrote:As food for thought, depending on what you are doing, it might be better to have a config file that gets included wherever the values are needed as a go between. That way you're not risking overwriting important stuff. And having one lua file write directly into another is O_o
That said, couldn't you just use a global variable?
Its a lua file that generates verilog code. I can't use a variable, because I don't know how many wires there are and what they will be named.
knorke wrote:or if you just want to add at the end of the file, "a" parameter is for append.
Can't append to the end of the file as the wires need to be defined before I use them ^^
zwzsg wrote:r read the whole file into a string. I have a widget that read files in the 50kb range into a string, apply some gsub to it, then write it to a file.
Yeah apparently lua is a beast at strings.
Because Lua handles long strings efficiently, a simple technique for writing filters in Lua is to read the whole file into a string, do the processing to the string (typically with gsub), and then write the string to the output:
t = io.read("*all") -- read the whole file
t = string.gsub(t, ...) -- do the job
io.write(t) -- write the file
ended up using this, worked perfectly.
I attached the file if anyone is interested in seeing what it does/how horribly noobish I am at lua.