All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] LUA script engine for grub2
@ 2009-04-07 14:31 Bean
  2009-04-07 15:18 ` phcoder
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Bean @ 2009-04-07 14:31 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 754 bytes --]

Hi,

This patch integrate the LUA script engine to grub2. Before applying
this patch, you should apply the split module patch split_3.diff
first.

BTW, I forget to add Makefile.in the previous split_3.diff, so that
handler.lst will not be generated, I include it in this one.

To try the LUA engine, you can enter command line, and use:

parser.lua

Inside lua, you can use grub.run to execute grub commands, such as:

grub.run("ls", "-l")

To switch back to sh, you can run this command:

grub.run("parser.sh")

Here is a small lua program to solve the hanoi tower:

function hanoi(n,a,b,c)
if (n == 1) then
  print ("move from", a, "to", c)
else
  hanoi (n-1, a, c, b)
  hanoi (1, a, b, c)
  hanoi (n-1, b, a, c)
end
end
hanoi (3, 1, 2, 3)



-- 
Bean

[-- Attachment #2: lua.zip --]
[-- Type: application/zip, Size: 116386 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] LUA script engine for grub2
  2009-04-07 14:31 [PATCH] LUA script engine for grub2 Bean
@ 2009-04-07 15:18 ` phcoder
  2009-04-07 16:15 ` Vesa Jääskeläinen
  2009-04-13 14:27 ` Robert Millan
  2 siblings, 0 replies; 12+ messages in thread
From: phcoder @ 2009-04-07 15:18 UTC (permalink / raw)
  To: The development of GRUB 2

Is it all from scratch? Wau. Very nice job. Unfortunately I don't know 
any lua but I'll test this as time permits
Bean wrote:
> Hi,
> 
> This patch integrate the LUA script engine to grub2. Before applying
> this patch, you should apply the split module patch split_3.diff
> first.
> 
> BTW, I forget to add Makefile.in the previous split_3.diff, so that
> handler.lst will not be generated, I include it in this one.
> 
> To try the LUA engine, you can enter command line, and use:
> 
> parser.lua
> 
> Inside lua, you can use grub.run to execute grub commands, such as:
> 
> grub.run("ls", "-l")
> 
> To switch back to sh, you can run this command:
> 
> grub.run("parser.sh")
> 
> Here is a small lua program to solve the hanoi tower:
> 
> function hanoi(n,a,b,c)
> if (n == 1) then
>   print ("move from", a, "to", c)
> else
>   hanoi (n-1, a, c, b)
>   hanoi (1, a, b, c)
>   hanoi (n-1, b, a, c)
> end
> end
> hanoi (3, 1, 2, 3)
> 
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel


-- 

Regards
Vladimir 'phcoder' Serbinenko



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] LUA script engine for grub2
  2009-04-07 14:31 [PATCH] LUA script engine for grub2 Bean
  2009-04-07 15:18 ` phcoder
@ 2009-04-07 16:15 ` Vesa Jääskeläinen
  2009-04-07 18:27   ` Bean
  2009-04-13 14:27 ` Robert Millan
  2 siblings, 1 reply; 12+ messages in thread
From: Vesa Jääskeläinen @ 2009-04-07 16:15 UTC (permalink / raw)
  To: The development of GRUB 2

Bean wrote:
> Hi,
> 
> This patch integrate the LUA script engine to grub2. Before applying
> this patch, you should apply the split module patch split_3.diff
> first.
> 
> BTW, I forget to add Makefile.in the previous split_3.diff, so that
> handler.lst will not be generated, I include it in this one.
> 
> To try the LUA engine, you can enter command line, and use:
> 
> parser.lua
> 
> Inside lua, you can use grub.run to execute grub commands, such as:
> 
> grub.run("ls", "-l")
> 
> To switch back to sh, you can run this command:
> 
> grub.run("parser.sh")

I would prefer something like grub.return or grub.exit, or something
like that if really needed.

Here is something that I would like that it can do:

In GUI definition:

action="lua:grub.run(\"ls\", \"-l\")" and action="my_lua_action.lua"

or just

action="lua:my_lua_action.lua"

and

action="ls -l" or action="(ba)sh:ls -l"

This way one could use both grub bash scripting and lua scripting.

Now if something is being executed in my_lua_action.lua and execution
comes to the end it should return to calling code.

grub_lua_execute_file("<file name to lua script>");
grub_lua_execute("<lua commands>");




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] LUA script engine for grub2
  2009-04-07 16:15 ` Vesa Jääskeläinen
@ 2009-04-07 18:27   ` Bean
  2009-04-08 14:40     ` Colin D Bennett
  0 siblings, 1 reply; 12+ messages in thread
From: Bean @ 2009-04-07 18:27 UTC (permalink / raw)
  To: The development of GRUB 2

2009/4/8 Vesa Jääskeläinen <chaac@nic.fi>:
> Bean wrote:
>> Hi,
>>
>> This patch integrate the LUA script engine to grub2. Before applying
>> this patch, you should apply the split module patch split_3.diff
>> first.
>>
>> BTW, I forget to add Makefile.in the previous split_3.diff, so that
>> handler.lst will not be generated, I include it in this one.
>>
>> To try the LUA engine, you can enter command line, and use:
>>
>> parser.lua
>>
>> Inside lua, you can use grub.run to execute grub commands, such as:
>>
>> grub.run("ls", "-l")
>>
>> To switch back to sh, you can run this command:
>>
>> grub.run("parser.sh")
>
> I would prefer something like grub.return or grub.exit, or something
> like that if really needed.

Hi,

I add a grub library to lua, now it only contain grub.run, but it
would be easy to add more function. I think it would be useful to add
function to interface with the video subsystem directly, so that lua
can be used to control the dynamic drawing of ui components.

> Here is something that I would like that it can do:
>
> In GUI definition:
>
> action="lua:grub.run(\"ls\", \"-l\")" and action="my_lua_action.lua"
>
> or just
>
> action="lua:my_lua_action.lua"
>
> and
>
> action="ls -l" or action="(ba)sh:ls -l"
>
> This way one could use both grub bash scripting and lua scripting.
>
> Now if something is being executed in my_lua_action.lua and execution
> comes to the end it should return to calling code.
>
> grub_lua_execute_file("<file name to lua script>");
> grub_lua_execute("<lua commands>");

In fact, I have extended the configfile command to accept parser parameter:

configfile /new_script.lua lua

or

source /script.lua lua

It would change to lua and parse script.lua, then switch back to the old parser.

-- 
Bean



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] LUA script engine for grub2
  2009-04-07 18:27   ` Bean
@ 2009-04-08 14:40     ` Colin D Bennett
  2009-04-08 17:02       ` Bean
  0 siblings, 1 reply; 12+ messages in thread
From: Colin D Bennett @ 2009-04-08 14:40 UTC (permalink / raw)
  To: grub-devel; +Cc: Bean

[-- Attachment #1: Type: text/plain, Size: 1115 bytes --]

Bean wrote:
> 2009/4/8 Vesa Jääskeläinen <chaac@nic.fi>:
> > Bean wrote:
> >> Hi,
> >>
> >> This patch integrate the LUA script engine to grub2

Cool!

> I add a grub library to lua, now it only contain grub.run, but it
> would be easy to add more function. I think it would be useful to add
> function to interface with the video subsystem directly, so that lua
> can be used to control the dynamic drawing of ui components.

I actually did some preliminary work to make this possible.  I made a demo 
where text is painted by a Lua script and it animates “flying by” on the 
screen.   (http://grub.gibibit.com/files/gfxmenu-lua-1.iso.gz for a demo ISO.)

Besides making the GRUB video API accessible (partially, so far) to Lua, I 
also made Lua able to implement GUI components in the graphical menu 
interface.  This is limited at this point and only paint() and destroy() 
methods can be implemented in Lua.  However, I think being able to implement 
new GUI components in Lua would be really great.

If my code would be any help to you, I can send it to you.

Regards,
Colin

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] LUA script engine for grub2
  2009-04-08 14:40     ` Colin D Bennett
@ 2009-04-08 17:02       ` Bean
  0 siblings, 0 replies; 12+ messages in thread
From: Bean @ 2009-04-08 17:02 UTC (permalink / raw)
  To: The development of GRUB 2

On Wed, Apr 8, 2009 at 10:40 PM, Colin D Bennett <colin@gibibit.com> wrote:
> Bean wrote:
>> 2009/4/8 Vesa Jääskeläinen <chaac@nic.fi>:
>> > Bean wrote:
>> >> Hi,
>> >>
>> >> This patch integrate the LUA script engine to grub2
>
> Cool!
>
>> I add a grub library to lua, now it only contain grub.run, but it
>> would be easy to add more function. I think it would be useful to add
>> function to interface with the video subsystem directly, so that lua
>> can be used to control the dynamic drawing of ui components.
>
> I actually did some preliminary work to make this possible.  I made a demo
> where text is painted by a Lua script and it animates “flying by” on the
> screen.   (http://grub.gibibit.com/files/gfxmenu-lua-1.iso.gz for a demo ISO.)
>
> Besides making the GRUB video API accessible (partially, so far) to Lua, I
> also made Lua able to implement GUI components in the graphical menu
> interface.  This is limited at this point and only paint() and destroy()
> methods can be implemented in Lua.  However, I think being able to implement
> new GUI components in Lua would be really great.
>
> If my code would be any help to you, I can send it to you.

Hi,

Oh, that looks great, just hope the new graphic interface can be merged soon.

For gui components, here is some of my thoughts. Perhaps we can add
api to register ui components, something like this:

grub_ui_register (&grub_menu_ui);

The structure may look like this:

struct grub_ui
{
  next
  name
  create
  destroy
  invoke
}

Then, we use an xml document to specify the screen layout and actions:

<grub ontimer="script1.draw_image()">
    <script id=script1 lang=lua>
       x = 100, y = 100
       function draw_image()
         x = x + 10
         grub.document.image1.move (x, y)
       end
    </script>
    <header id=header1 x= y= width= height= class= text=>
    </header>
    <menu id=menu1 x= y= width= height= class=>
    </menu>
    <image id=image1 src= x= y=>
    </image>
<grub>

In create function, we pass the attributes so that ui knows how to draw itself.
The ui can also implement extra named method, for example, image can
have move method. To call them, we can use the invoke function, for
example:

invoke ("move", argc, argv);

A similar interface can be implemented for lua ui components.

-- 
Bean



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] LUA script engine for grub2
  2009-04-07 14:31 [PATCH] LUA script engine for grub2 Bean
  2009-04-07 15:18 ` phcoder
  2009-04-07 16:15 ` Vesa Jääskeläinen
@ 2009-04-13 14:27 ` Robert Millan
  2009-04-14 15:33   ` Yoshinori K. Okuji
  2 siblings, 1 reply; 12+ messages in thread
From: Robert Millan @ 2009-04-13 14:27 UTC (permalink / raw)
  To: The development of GRUB 2; +Cc: Yoshinori K. Okuji

On Tue, Apr 07, 2009 at 10:31:44PM +0800, Bean wrote:
> Hi,
> 
> This patch integrate the LUA script engine to grub2.

Hi,

I don't have any opinion for or against using LUA, but note that we need
approval from Marco or Okuji before we can integrate external code.

-- 
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] LUA script engine for grub2
  2009-04-13 14:27 ` Robert Millan
@ 2009-04-14 15:33   ` Yoshinori K. Okuji
  2009-04-14 16:18     ` Bean
  0 siblings, 1 reply; 12+ messages in thread
From: Yoshinori K. Okuji @ 2009-04-14 15:33 UTC (permalink / raw)
  To: The development of GRUB 2

On Monday 13 April 2009 23:27:32 Robert Millan wrote:
> On Tue, Apr 07, 2009 at 10:31:44PM +0800, Bean wrote:
> > Hi,
> >
> > This patch integrate the LUA script engine to grub2.
>
> Hi,
>
> I don't have any opinion for or against using LUA, but note that we need
> approval from Marco or Okuji before we can integrate external code.

As long as LUA does not become the first citizen in GRUB (i.e. not essential 
in using GRUB), no problem.

Regards,
Okuji



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] LUA script engine for grub2
  2009-04-14 15:33   ` Yoshinori K. Okuji
@ 2009-04-14 16:18     ` Bean
  2009-05-03  8:46       ` Bean
  0 siblings, 1 reply; 12+ messages in thread
From: Bean @ 2009-04-14 16:18 UTC (permalink / raw)
  To: The development of GRUB 2

Hi,

Oh nice, can you confirm that there is no license conflict in porting
code from lua ?

On Tue, Apr 14, 2009 at 11:33 PM, Yoshinori K. Okuji <okuji@enbug.org> wrote:
> On Monday 13 April 2009 23:27:32 Robert Millan wrote:
>> On Tue, Apr 07, 2009 at 10:31:44PM +0800, Bean wrote:
>> > Hi,
>> >
>> > This patch integrate the LUA script engine to grub2.
>>
>> Hi,
>>
>> I don't have any opinion for or against using LUA, but note that we need
>> approval from Marco or Okuji before we can integrate external code.
>
> As long as LUA does not become the first citizen in GRUB (i.e. not essential
> in using GRUB), no problem.
>
> Regards,
> Okuji
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>



-- 
Bean



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] LUA script engine for grub2
  2009-04-14 16:18     ` Bean
@ 2009-05-03  8:46       ` Bean
  2009-05-16 12:37         ` Bean
  0 siblings, 1 reply; 12+ messages in thread
From: Bean @ 2009-05-03  8:46 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 3122 bytes --]

Hi,

This is an update for lua script engine. Now there are three commands
in the grub library:

grub.run
Execute a grub command, the command is now passed as a single string,
this allows users to construct it dynamically. Return grub_errno, the
error message is returned as second value if grub_errno is not 0.

Example:
err_no,err_msg=grub.run("ls /")
print(err_no,err_msg)


grub.getenv
Get grub environment variable. Allow multiple input.

Example:
prefix,root=grub.getenv("prefix", "root")

grub.setenv
Set grub environment variable.

Example:
grub.setenv ("aa", "Hello")
grub.run("set")

The grub code is now completely separated from lua code, it always
starts with grub_ prefix: grub_main.c, grub_lua.h, grub_lib.c and
grub_lib.h.

If there is no objection, I'd commit this in a few days.

2009-05-03  Bean  <bean123ch@gmail.com>

	* conf/common.rmk (pkglib_MODULES): Add lua.mod.
	(lua_mod_SOURCES): New variable.
	(lua_mod_CFLAGS): Likewise.
	(lua_mod_LDFLAGS): Likewise.

	* conf/i386.rmk (pkglib_MODULES): Add setjmp.mod.
	(setjmp_mod_SOURCES): New variable.
	(setjmp_mod_CFLAGS): Likewise.
	(setjmp_LDFLAGS): Likewise.

	* include/grub/i386/setjmp.h (grub_setjmp): Don't use attribute
	returns_twice in mingw.

	* script/lua/grub_lib.c: New file.
	* script/lua/grub_lib.h: Likewise.
	* script/lua/grub_lua.h: Likewise.
	* script/lua/grub_main.c: Likewise.
	* script/lua/lapi.c: Likewise.
	* script/lua/lapi.h: Likewise.
	* script/lua/lauxlib.c: Likewise.
	* script/lua/lauxlib.h: Likewise.
	* script/lua/lbaselib.c: Likewise.
	* script/lua/lcode.c: Likewise.
	* script/lua/lcode.h: Likewise.
	* script/lua/ldblib.c: Likewise.
	* script/lua/ldebug.c: Likewise.
	* script/lua/ldebug.h: Likewise.
	* script/lua/ldo.c: Likewise.
	* script/lua/ldo.h: Likewise.
	* script/lua/ldump.c: Likewise.
	* script/lua/lfunc.c: Likewise.
	* script/lua/lfunc.h: Likewise.
	* script/lua/lgc.c: Likewise.
	* script/lua/lgc.h: Likewise.
	* script/lua/linit.c: Likewise.
	* script/lua/liolib.c: Likewise.
	* script/lua/llex.c: Likewise.
	* script/lua/llex.h: Likewise.
	* script/lua/llimits.h: Likewise.
	* script/lua/lmathlib.c: Likewise.
	* script/lua/lmem.c: Likewise.
	* script/lua/lmem.h: Likewise.
	* script/lua/loadlib.c: Likewise.
	* script/lua/lobject.c: Likewise.
	* script/lua/lobject.h: Likewise.
	* script/lua/lopcodes.c: Likewise.
	* script/lua/lopcodes.h: Likewise.
	* script/lua/loslib.c: Likewise.
	* script/lua/lparser.c: Likewise.
	* script/lua/lparser.h: Likewise.
	* script/lua/lstate.c: Likewise.
	* script/lua/lstate.h: Likewise.
	* script/lua/lstring.c: Likewise.
	* script/lua/lstring.h: Likewise.
	* script/lua/lstrlib.c: Likewise.
	* script/lua/ltable.c: Likewise.
	* script/lua/ltable.h: Likewise.
	* script/lua/ltablib.c: Likewise.
	* script/lua/ltm.c: Likewise.
	* script/lua/ltm.h: Likewise.
	* script/lua/lua.h: Likewise.
	* script/lua/luaconf.h: Likewise.
	* script/lua/lualib.h: Likewise.
	* script/lua/lundump.c: Likewise.
	* script/lua/lundump.h: Likewise.
	* script/lua/lvm.c: Likewise.
	* script/lua/lvm.h: Likewise.
	* script/lua/lzio.c: Likewise.
	* script/lua/lzio.h: Likewise.


-- 
Bean

[-- Attachment #2: lua_2.zip --]
[-- Type: application/zip, Size: 116559 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] LUA script engine for grub2
  2009-05-03  8:46       ` Bean
@ 2009-05-16 12:37         ` Bean
  2009-05-16 13:31           ` Felix Zielcke
  0 siblings, 1 reply; 12+ messages in thread
From: Bean @ 2009-05-16 12:37 UTC (permalink / raw)
  To: The development of GRUB 2

Hi,

Committed.

-- 
Bean



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] LUA script engine for grub2
  2009-05-16 12:37         ` Bean
@ 2009-05-16 13:31           ` Felix Zielcke
  0 siblings, 0 replies; 12+ messages in thread
From: Felix Zielcke @ 2009-05-16 13:31 UTC (permalink / raw)
  To: The development of GRUB 2

Am Samstag, den 16.05.2009, 20:37 +0800 schrieb Bean:
> Hi,
> 
> Committed.

Hi Bean,

I think it would be good if you could document this in the Wiki.
-- 
Felix Zielcke




^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2009-05-16 13:32 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-07 14:31 [PATCH] LUA script engine for grub2 Bean
2009-04-07 15:18 ` phcoder
2009-04-07 16:15 ` Vesa Jääskeläinen
2009-04-07 18:27   ` Bean
2009-04-08 14:40     ` Colin D Bennett
2009-04-08 17:02       ` Bean
2009-04-13 14:27 ` Robert Millan
2009-04-14 15:33   ` Yoshinori K. Okuji
2009-04-14 16:18     ` Bean
2009-05-03  8:46       ` Bean
2009-05-16 12:37         ` Bean
2009-05-16 13:31           ` Felix Zielcke

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.