interface
| 1602 | |
| 1603 | // interface |
| 1604 | int asCScriptEngine::RegisterObjectProperty(const char *obj, const char *declaration, int byteOffset, int compositeOffset, bool isCompositeIndirect) |
| 1605 | { |
| 1606 | int r; |
| 1607 | asCDataType dt; |
| 1608 | asCBuilder bld(this, 0); |
| 1609 | r = bld.ParseDataType(obj, &dt, defaultNamespace); |
| 1610 | if( r < 0 ) |
| 1611 | return ConfigError(r, "RegisterObjectProperty", obj, declaration); |
| 1612 | |
| 1613 | if (dt.GetTypeInfo() == 0 || (dt.IsObjectHandle() && !(dt.GetTypeInfo()->GetFlags() & asOBJ_IMPLICIT_HANDLE))) |
| 1614 | return ConfigError(asINVALID_OBJECT, "RegisterObjectProperty", obj, declaration); |
| 1615 | |
| 1616 | // Don't allow modifying generated template instances |
| 1617 | if( dt.GetTypeInfo() && (dt.GetTypeInfo()->flags & asOBJ_TEMPLATE) && generatedTemplateTypes.Exists(CastToObjectType(dt.GetTypeInfo())) ) |
| 1618 | return ConfigError(asINVALID_TYPE, "RegisterObjectProperty", obj, declaration); |
| 1619 | |
| 1620 | // Verify that the correct config group is used |
| 1621 | if( currentGroup->FindType(dt.GetTypeInfo()->name.AddressOf()) == 0 ) |
| 1622 | return ConfigError(asWRONG_CONFIG_GROUP, "RegisterObjectProperty", obj, declaration); |
| 1623 | |
| 1624 | asCDataType type; |
| 1625 | asCString name; |
| 1626 | |
| 1627 | if( (r = bld.VerifyProperty(&dt, declaration, name, type, 0)) < 0 ) |
| 1628 | return ConfigError(r, "RegisterObjectProperty", obj, declaration); |
| 1629 | |
| 1630 | // The VM currently only supports 16bit offsets |
| 1631 | // TODO: The VM needs to have support for 32bit offsets. Probably with a second ADDSi instruction |
| 1632 | // However, when implementing this it is necessary for the bytecode serialization to support |
| 1633 | // the switch between the instructions upon loading bytecode as the offset may not be the |
| 1634 | // same on all platforms |
| 1635 | if( byteOffset > 32767 || byteOffset < -32768 ) |
| 1636 | return ConfigError(asINVALID_ARG, "RegisterObjectProperty", obj, declaration); |
| 1637 | // The composite offset must also obey the ADDSi restriction |
| 1638 | if (compositeOffset > 32767 || compositeOffset < -32768) |
| 1639 | return ConfigError(asINVALID_ARG, "RegisterObjectProperty", obj, declaration); |
| 1640 | |
| 1641 | asCObjectProperty *prop = asNEW(asCObjectProperty); |
| 1642 | if( prop == 0 ) |
| 1643 | return ConfigError(asOUT_OF_MEMORY, "RegisterObjectProperty", obj, declaration); |
| 1644 | |
| 1645 | prop->name = name; |
| 1646 | prop->type = type; |
| 1647 | prop->byteOffset = byteOffset; |
| 1648 | prop->isPrivate = false; |
| 1649 | prop->isProtected = false; |
| 1650 | prop->compositeOffset = compositeOffset; |
| 1651 | prop->isCompositeIndirect = isCompositeIndirect; |
| 1652 | prop->accessMask = defaultAccessMask; |
| 1653 | |
| 1654 | asCObjectType *ot = CastToObjectType(dt.GetTypeInfo()); |
| 1655 | asUINT idx = ot->properties.GetLength(); |
| 1656 | ot->properties.PushLast(prop); |
| 1657 | |
| 1658 | // Add references to types so they are not released too early |
| 1659 | if( type.GetTypeInfo() ) |
| 1660 | { |
| 1661 | type.GetTypeInfo()->AddRefInternal(); |