[Gambas-user] Gambas Scripting Language - Some Questions

Sergio A. Hernandez info.geex at ...626...
Thu May 21 06:13:04 CEST 2009


2009/5/18 Benoît Minisini <gambas at ...1...>

> > Hello all,
> > I have some questions about the scripting language. I need a little help.
> > Question
> >
> > Thanks in advance, and have a nice weekend.
> >
>
> The scripter works by creating a temporary project from your script, by
> compiling it, and by running it. The compiled project is cached so that it
> is
> used immediately if you run the script again.
>
> So:
>
> > 1- The gbs2 scripter only have access to the gb. internal native class?
>
> No, it can use any component.
>
> > 2- How can I use other components as the gb.XML?
>
> By using the special instruction USE. For example:
>
> USE "gb.xml","gb.xml.rpc"
>
> > 3- Why my scripts dont run directly even when I am including the first
> > line #!/usr/bin/env gbs2?
>
> Two possible reasons:
>
> - The gbs2 symbolic link does not exist.
>
> - It exists, but is not in a directory specified in your PATH environment
> variable.
>
> > 4- How can I pass arguments to the script?
>
> Just pass them:
>
> $ MyScript A B C
>
> Regards,
>
> --
> Benoît
>
> Hello again, I am trying to run this script base on what you guys suggest
me, however I received the following error message:
MMain.GenerateFiles.234: This component doesn't exist : "gb.xml"
0: MMain.GenerateFiles.234
1: MMain.MakeVirtualProject.140
2: MMain.Main.61

#!/usr/bin/env gbs2
USE "gb.xml"
PUBLIC SUB Main()
 DIM writer AS XmlWriter

 writer = NEW XmlWriter
 writer.Open(User.Home & "/Heroes.xml", TRUE)
 writer.Comment("Heroes Characters")

 writer.StartElement("characters")
  writer.Attribute("series", "Heroes")

  writer.StartElement("heroe")
   writer.Attribute("id", "1")
   writer.Attribute("name", "Claire Bennet")
   writer.StartElement("name")
    writer.Text("Claire Bennet")
   writer.EndElement 'name
   writer.StartElement("played_by")
    writer.Text("Hayden Panettiere")
   writer.EndElement 'played_by
   writer.StartElement("ability")
    writer.Text("Rapid cellular regeneration")
   writer.EndElement 'ability
  writer.EndElement 'heroe

  writer.StartElement("heroe", ["id", "2", "name", "Hiro Nakamura"])
   writer.Element("name", "Hiro Nakamura")
   writer.Element("played_by", "Masi Oka")
   writer.Element("ability", "Space-time manipulation: teleportation & time
travel")
  writer.EndElement 'heroe

  writer.StartElement("villain", ["id", "3", "name", "Gabriel Sylar"])
   writer.Element("name", "Gabriel Sylar")
   writer.Element("played_by", "Zachary Quinto")
   writer.Element("ability", "Understand how things work and multiple other
abilities acquired")
  writer.EndElement 'villain

 writer.EndElement 'character

 PRINT writer.EndDocument()
END

To create the following xml file
<?xml version="1.0"?>
<!--Heroes Characters-->
<characters series="Heroes">
 <heroe id="1" name="Claire Bennet">
  <name>Claire Bennet</name>
  <played_by>Hayden Panettiere</played_by>
  <ability>Rapid cellular regeneration</ability>
 </heroe>
 <heroe id="2" name="Hiro Nakamura">
  <name>Hiro Nakamura</name>
  <played_by>Masi Oka</played_by>
  <ability>Space-time manipulation: teleportation & time
travel</ability>
 </heroe>
 <villain id="3" name="Gabriel Sylar">
  <name>Gabriel Sylar</name>
  <played_by>Zachary Quinto</played_by>
  <ability>Understand how things work and multiple other abilities
acquired</ability>
 </villain>
</characters>
I want to include this example on the spanish wikibook for Gambas, actually
I already included but I can make it work.
http://es.wikibooks.org/wiki/Gambas/Scripting_con_Gambas



More information about the User mailing list