+naRef f_canvasCreateGroup(sc::Canvas& canvas, const nasal::CallContext& ctx)
+{
+ return NasalGroup::create
+ (
+ ctx.c,
+ canvas.createGroup( ctx.getArg<std::string>(0) )
+ );
+}
+
+/**
+ * Get group containing all gui windows
+ */
+naRef f_getDesktop(naContext c, naRef me, int argc, naRef* args)
+{
+ return NasalGroup::create(c, requireGUIMgr(c).getDesktop());
+}
+
+naRef f_groupCreateChild(sc::Group& group, const nasal::CallContext& ctx)
+{
+ return NasalElement::create
+ (
+ ctx.c,
+ group.createChild( ctx.requireArg<std::string>(0),
+ ctx.getArg<std::string>(1) )
+ );
+}
+
+naRef f_groupGetChild(sc::Group& group, const nasal::CallContext& ctx)
+{
+ return NasalElement::create
+ (
+ ctx.c,
+ group.getChild( ctx.requireArg<SGPropertyNode*>(0) )
+ );
+}
+
+naRef f_groupGetElementById(sc::Group& group, const nasal::CallContext& ctx)
+{
+ return NasalElement::create
+ (
+ ctx.c,
+ group.getElementById( ctx.requireArg<std::string>(0) )
+ );
+}
+
+static void propElementSetData( simgear::PropertyBasedElement& el,
+ const std::string& name,
+ naContext c,
+ naRef ref )
+{
+ if( naIsNil(ref) )
+ return el.removeDataProp(name);
+
+ std::string val = nasal::from_nasal<std::string>(c, ref);
+
+ char* end = NULL;
+
+ long val_long = strtol(val.c_str(), &end, 10);
+ if( !*end )
+ return el.setDataProp(name, val_long);
+
+ double val_double = strtod(val.c_str(), &end);
+ if( !*end )
+ return el.setDataProp(name, val_double);
+
+ el.setDataProp(name, val);
+}
+
+/**
+ * Accessor for HTML5 data properties.
+ *
+ * # set single property:
+ * el.data("myKey", 5);
+ *
+ * # set multiple properties
+ * el.data({myProp1: 12, myProp2: "test"});
+ *
+ * # get value of properties
+ * el.data("myKey"); # 5
+ * el.data("myProp2"); # "test"
+ *
+ * # remove a single property
+ * el.data("myKey", nil);
+ *
+ * # remove multiple properties
+ * el.data({myProp1: nil, myProp2: nil});
+ *
+ * # set and remove multiple properties
+ * el.data({newProp: "some text...", removeProp: nil});
+ *
+ *
+ * @see http://api.jquery.com/data/
+ */
+static naRef f_propElementData( simgear::PropertyBasedElement& el,
+ const nasal::CallContext& ctx )
+{
+ if( ctx.isHash(0) )
+ {
+ // Add/delete properties given as hash
+ nasal::Hash obj = ctx.requireArg<nasal::Hash>(0);
+ for(nasal::Hash::iterator it = obj.begin(); it != obj.end(); ++it)
+ propElementSetData(el, it->getKey(), ctx.c, it->getValue<naRef>());
+
+ return ctx.to_nasal(&el);
+ }
+
+ std::string name = ctx.getArg<std::string>(0);
+ if( !name.empty() )
+ {
+ if( ctx.argc == 1 )
+ {
+ // name + additional argument -> add/delete property
+ SGPropertyNode* node = el.getDataProp<SGPropertyNode*>(name);
+ if( !node )
+ return naNil();
+
+ return ctx.to_nasal( node->getStringValue() );
+ }
+ else
+ {
+ // only name -> get property
+ propElementSetData(el, name, ctx.c, ctx.requireArg<naRef>(1));
+ return ctx.to_nasal(&el);
+ }
+ }
+
+ return naNil();
+}
+
+template<int Mask>
+naRef f_eventGetModifier(sc::MouseEvent& event, naContext)
+{
+ return naNum((event.getModifiers() & Mask) != 0);
+}
+
+static naRef f_createCustomEvent(const nasal::CallContext& ctx)