grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] File access library for lua


From: Bean
Subject: [PATCH] File access library for lua
Date: Sun, 21 Jun 2009 19:33:51 +0800

Hi,

I've added a few function in the lua grub library to access files:

enum_device - enumerate devices
enum_file - enumerate files
file_open - open file
file_close - close file
file_seek - seek file
file_read - read n bytes
file_getline - read a line
file_getsize - get file size
file_getpos - get current read position

Here is an example:

#!lua

function enum_device (name)
  print (name)
  return 0
end

function enum_file (name, is_dir)
  print (is_dir, name)
  return 0
end

grub.enum_device (enum_device)
grub.enum_file ("/boot/grub", enum_file)
f = grub.file_open ("/boot/grub/grub.cfg")
print (grub.file_getsize (f))
print (grub.file_getline (f))
print (grub.file_getline (f))
print (grub.file_seek (f, 0))
print (grub.file_read (f, 10))
print (grub.file_getpos (f))
grub.file_close (f);

And now after file operation, the result is saved in global variable
grub_errno and grub_errmsg (lua variable), for example:
f = grub.file_open ("/abcde")
if (f == nil) then
  print (grub_errno, grub_errmsg)
fi

I also enable the string library from lua.

-- 
Bean

Attachment: lua_file.diff
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]