1. Summary
  2. Files
  3. Support
  4. Report Spam
  5. Create account
  6. Log in

Giraffe Script

Giraffe Script is the language which is created as the extension language for the launcher Giraffe+.

How to evaluate a script

With Giraffe+, input a script and type F1, or copy a script and input get-cb.eval.flush and type F1, or save a script to a file and run Giraffe.exe with the file name as a command line argument. With gs.exe, run the command line "gs --eval script", or save a script to a file and run "gs --file the_file_name".

Motivation

My launcher, Giraffe+, had the extension language which was so plain that I wanted to extend it. Fisrt, I read documents of famous extension script languages or libraries, such as Lua, Io, Boost.Python, Swig, Clipp and so on, to use it as the new extension language. Though, they were not what I wanted, and I decided to create my language as many languages' authors did.

What I wanted the language to be is:

  • C++-friendly
  • Prototype-based
  • Functional

And also I decided to make the language able to use scripts and DLLs of my old language without modification. However, this decision made the new language a little bit clumsy.

Sample

A string which starts with // is a comment.

C++-Friendly Sample

The C++ standard library and Boost libraries are used as standard library of this language.

'abc'.to_upper //boost::to_upper is called and 'ABC' is returned.
'abc'.size //std::wstring::size is called and 3 is returnd.
1..100.accumulate //std::accumulate is called and 5050 is returned.

Functional Sample

The map function can be defined as functional as below. (Though, Container.map is available.)

map: `f {x xs.@}[ //{} destructures an array; .@ takes the rest arguments as an range.
  {f(x) recur(f$ xs).@}  //{} makes an array; .@ expands the array to arguments.
].| `f {}[ //.| makes an overloaded function.
  {} //an empty array is just returned; an explicit return statement isn't needed.
]

map(`n[n.* 2] {1 2 3}) //{2 4 6} is returned.

Practical Sample

This is the script from Giraffe+ which shows file counts of directories in ListBox.

ec: Error_code.clone //clone makes a new object.

Giraffe.ListBox.each& `i[ //each iterates elements.
  d: i.Text.dir(ec) //dir makes the directory range.
  ec.! [ //this means "unless an error occured"
    i.SetDisplayText(i.Text.+ \\t.+ (d.size.to_String)) //d.size returns file counts of the directory.
  ]
]

Giraffe.ListBox.Invalidate //CListBox::Invalidate of MFC is called and the ListBox is redrawn.

In C++

From the ref_test function in GiraffeScriptTest.cpp.

gs::global_Context c;

gstring strValue = L"test";
c.def(L"ref_value", c.wrap_ref(strValue));
c.eval_string(L"ref_value.+=' is done'");
BOOST_CHECK_EQUAL(strValue, L"test is done");

Language Reference

Grammar
Slot
Inheritance
Conditional
Object
Context
Container
Indexing
Method
Block
Type
Constness
Cast
Number
String
Regex?
Array?
Map?
Range?
Nil
Null Object
Interpreter?
IO Stream?
File System?
DLL?
Structure?
Pointer?