"use strict";(self.webpackChunkdocs_site=self.webpackChunkdocs_site||[]).push([[8552],{8453:(e,n,l)=>{l.d(n,{R:()=>r,x:()=>o});var i=l(6540);const s={},t=i.createContext(s);function r(e){const n=i.useContext(t);return i.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:r(e.components),i.createElement(t.Provider,{value:n},e.children)}},8970:(e,n,l)=>{l.r(n),l.d(n,{assets:()=>a,contentTitle:()=>o,default:()=>u,frontMatter:()=>r,metadata:()=>i,toc:()=>c});const i=JSON.parse('{"id":"XXTLanControl.lua/web-file/set_line","title":"Replace A Single Line (LCC.web_file.set_line)","description":"Signature","source":"@site/i18n/en/docusaurus-plugin-content-docs/current/XXTLanControl.lua/web-file/set_line.md","sourceDirName":"XXTLanControl.lua/web-file","slug":"/XXTLanControl.lua/web-file/set_line","permalink":"/docs/en/XXTLanControl.lua/web-file/set_line","draft":false,"unlisted":false,"tags":[],"version":"current","sidebarPosition":200,"frontMatter":{"sidebar_position":200},"sidebar":"tutorialSidebar","previous":{"title":"Replace A Range Of Lines (LCC.web_file.set_range_lines)","permalink":"/docs/en/XXTLanControl.lua/web-file/set_range_lines"},"next":{"title":"Insert Multiple Lines (LCC.web_file.insert_lines)","permalink":"/docs/en/XXTLanControl.lua/web-file/insert_lines"}}');var s=l(4848),t=l(8453);const r={sidebar_position:200},o="Replace A Single Line (LCC.web_file.set_line)",a={},c=[{value:"Signature",id:"signature",level:2},{value:"Parameters",id:"parameters",level:2},{value:"Returns",id:"returns",level:2},{value:"Notes",id:"notes",level:2},{value:"Example",id:"example",level:2}];function d(e){const n={blockquote:"blockquote",br:"br",code:"code",h1:"h1",h2:"h2",header:"header",li:"li",p:"p",pre:"pre",ul:"ul",...(0,t.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.header,{children:(0,s.jsx)(n.h1,{id:"replace-a-single-line-lccweb_fileset_line",children:"Replace A Single Line (LCC.web_file.set_line)"})}),"\n",(0,s.jsx)(n.h2,{id:"signature",children:"Signature"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-lua",children:"ok, old_line_or_err = LCC.web_file.set_line(path, line_number, line, timeout?)\n"})}),"\n",(0,s.jsx)(n.h2,{id:"parameters",children:"Parameters"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["path",(0,s.jsx)(n.br,{}),"\n","String. File path."]}),"\n",(0,s.jsxs)(n.li,{children:["line_number",(0,s.jsx)(n.br,{}),"\n","Number. Line index to write; positive numbers start at ",(0,s.jsx)(n.code,{children:"1"}),", negative values count from the end (",(0,s.jsx)(n.code,{children:"-1"})," is the last line), and ",(0,s.jsx)(n.code,{children:"0"})," means after the last line."]}),"\n",(0,s.jsxs)(n.li,{children:["line",(0,s.jsx)(n.br,{}),"\n","String. New content."]}),"\n",(0,s.jsxs)(n.li,{children:["timeout",(0,s.jsx)(n.br,{}),"\n","Number, optional. Request timeout in seconds, default ",(0,s.jsx)(n.code,{children:"60"}),"."]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"returns",children:"Returns"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["ok",(0,s.jsx)(n.br,{}),"\n","Boolean. ",(0,s.jsx)(n.code,{children:"true"})," on success, ",(0,s.jsx)(n.code,{children:"false"})," on failure."]}),"\n",(0,s.jsxs)(n.li,{children:["old_line_or_err",(0,s.jsx)(n.br,{}),"\n","String or ",(0,s.jsx)(n.code,{children:"nil"}),". Previous text when successful; ",(0,s.jsx)(n.code,{children:"nil"})," when no existing line was replaced; error description when the call fails."]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"notes",children:"Notes"}),"\n",(0,s.jsxs)(n.blockquote,{children:["\n",(0,s.jsxs)(n.p,{children:["Wrapper around ",(0,s.jsx)(n.code,{children:"set_range_lines"})," for single-line edits.",(0,s.jsx)(n.br,{}),"\n","See the parameter description above for line-number rules.",(0,s.jsx)(n.br,{}),"\n","Returns the previous text so you can compare or roll back.",(0,s.jsx)(n.br,{}),"\n","Writing beyond the current content still creates a new line, with ",(0,s.jsx)(n.code,{children:"nil"})," as the old value."]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-lua",children:'local ok, old_line = LCC.web_file.set_line("/config/list.txt", 1, "Alpha")\nif ok then\n    print("Old text: " .. (old_line or ""))\nend\n'})})]})}function u(e={}){const{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}}}]);