1) From The Hello World Collection implement Cmd;
implement Cmd;
include "sys.m";
include "draw.m";
Cmd : module {
init : fn (ctxt : ref Draw->Context, args : list of string);
};
init(nil : ref Draw->Context, nil : list of string)
{
sys := load Sys Sys->PATH;
sys->print("Hello World\n");
}
2) From VN Limbo basics which also contains a very good line by line walk through
implement Command;
include "sys.m";
sys: Sys;
include "draw.m";
Command: module
{
init: fn(nil: ref Draw->Context, argv: list of string);
};
init(nil: ref Draw->Context, argv: list of string)
{
sys = load Sys Sys->PATH;
# check for command-line arguments
if(tl argv != nil)
sys->print("Hello, %s!\n", hd tl argv);
else
sys->print("Hello, World!\n");
}
3) From Inferno Programming With Limbo
helloworld.m
#
# Software from the book "Inferno Programming with Limbo"
# published by John Wiley & Sons, January 2003.
#
# p. Stanley-Marbell <pip@gemusehaken.org>
#
HelloWorld : module
{
init : fn(ctxt: ref Draw->Context, args : list of string);
};
helloworld.b
#
# Software from the book "Inferno Programming with Limbo"
# published by John Wiley & Sons, January 2003.
#
# p. Stanley-Marbell <pip@gemusehaken.org>
#
implement HelloWorld;
include "sys.m";
include "draw.m";
include "helloworld.m";
init(ctxt : ref Draw->Context, args : list of string)
{
sys : Sys;
# This is a comment
sys = load Sys Sys->PATH;
sys->print("Hello World !");
}
4) A Tk Hello World
implement Tk0;
include "draw.m";
include "sys.m";
sys: Sys;
include "tk.m";
tk: Tk;
Toplevel: import tk;
include "tkclient.m";
tkclient: Tkclient;
Tk0: module
{
init: fn(ctxt: ref Draw->Context, argv: list of string);
};
init(ctxt: ref Draw->Context, nil: list of string)
{
sys = load Sys Sys->PATH;
tk = load Tk Tk->PATH;
tkclient = load Tkclient Tkclient->PATH;
sys->pctl(Sys->NEWPGRP|Sys->FORKNS, nil);
tkclient->init();
(top, ctl) := tkclient->toplevel(ctxt, nil, "Tk0", Tkclient->Appl);
tkclient->startinput(top, "ptr" :: "kbd" :: nil);
tk->cmd(top, "button .b -text {hello, world}");
tk->cmd(top, "pack .b");
tk->cmd(top, "update");
tkclient->onscreen(top, nil);
for(;;) alt {
s := <-ctl or
s = <-top.ctxt.ctl or
s = <-top.wreq =>
tkclient->wmctl(top, s);
p := <-top.ctxt.ptr =>
tk->pointer(top, *p);
c := <-top.ctxt.kbd =>
tk->keyboard(top, c);
}
}
cmd(t: ref Toplevel, arg: string): string
{
rv := tk->cmd(t,arg);
if(rv!=nil && rv[0]=='!')
sys->print("tk->cmd(%s): %s\n",arg,rv);
return rv;
}
| Last modified Wed May 21 14:03:27 EDT 2008 | [ Top | Edit | History | Changelog | Create a new page ] | About the server | inferno |