File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
internal/luapi/lua_global Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,8 @@ func (l *Lua) init() {
6565 l .SetGlobal ("vmrGetOsEnv" , GetOsEnv )
6666 l .SetGlobal ("vmrSetOsEnv" , SetOsEnv )
6767 l .SetGlobal ("vmrExecSystemCmd" , ExecSystemCmd )
68+ l .SetGlobal ("vmrReadFile" , ReadFile )
69+ l .SetGlobal ("vmrWriteFile" , WriteFile )
6870 // version
6971 l .SetGlobal ("vmrNewVersionList" , NewVersionList )
7072 l .SetGlobal ("vmrAddItem" , AddItem )
Original file line number Diff line number Diff line change @@ -203,3 +203,40 @@ func ExecSystemCmd(L *lua.LState) int {
203203
204204 return 2
205205}
206+
207+ /*
208+ lua: string = vmrReadFile(filePath string)
209+ */
210+ func ReadFile (L * lua.LState ) int {
211+ filePath := L .ToString (1 )
212+ if filePath == "" {
213+ L .Push (lua .LString ("" ))
214+ return 1
215+ }
216+ content , err := os .ReadFile (filePath )
217+ if err != nil {
218+ L .Push (lua .LString ("" ))
219+ return 1
220+ }
221+ L .Push (lua .LString (string (content )))
222+ return 1
223+ }
224+
225+ /*
226+ lua: bool = vmrWriteFile(filePath string)
227+ */
228+ func WriteFile (L * lua.LState ) int {
229+ filePath := L .ToString (1 )
230+ content := L .ToString (2 )
231+ if filePath == "" {
232+ L .Push (lua .LFalse )
233+ return 1
234+ }
235+ err := os .WriteFile (filePath , []byte (content ), os .ModePerm )
236+ if err != nil {
237+ L .Push (lua .LFalse )
238+ } else {
239+ L .Push (lua .LTrue )
240+ }
241+ return 1
242+ }
You can’t perform that action at this time.
0 commit comments