Skip to content

Commit

Permalink
Traktor: Exposed Reader class to script. Inlined Any constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed Jan 23, 2024
1 parent 5b47459 commit 45908d0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
14 changes: 1 addition & 13 deletions code/Core/Class/Any.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -60,11 +60,6 @@ char* refStringDec(char* s)

}

Any::Any()
: m_type(Type::Void)
{
}

Any::Any(const Any& src)
: m_type(src.m_type)
{
Expand All @@ -79,13 +74,6 @@ Any::Any(const Any& src)
m_data = src.m_data;
}

Any::Any(Any&& src) noexcept
: m_type(src.m_type)
, m_data(src.m_data)
{
src.m_type = Type::Void;
}

Any::~Any()
{
T_EXCEPTION_GUARD_BEGIN
Expand Down
14 changes: 11 additions & 3 deletions code/Core/Class/Any.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -48,11 +48,19 @@ class T_DLLCLASS Any
Object
};

Any();
Any()
: m_type(Type::Void)
{
}

Any(const Any& src);

Any(Any&& src) noexcept;
Any(Any&& src) noexcept
: m_type(src.m_type)
, m_data(src.m_data)
{
src.m_type = Type::Void;
}

virtual ~Any();

Expand Down
15 changes: 14 additions & 1 deletion code/Core/Class/CoreClassFactory1.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -19,6 +19,7 @@
#include "Core/Io/DynamicMemoryStream.h"
#include "Core/Io/FileSystem.h"
#include "Core/Io/MemoryStream.h"
#include "Core/Io/Reader.h"
#include "Core/Io/StreamCopy.h"
#include "Core/Io/StringReader.h"
#include "Core/Io/Utf8Encoding.h"
Expand Down Expand Up @@ -46,6 +47,12 @@ namespace traktor
namespace
{

float Reader_readFloat(Reader* self)
{
float v; *self >> v;
return v;
}

Ref< Path > Path_concat(Path* self, Path* rh)
{
return new Path(*self + *rh);
Expand Down Expand Up @@ -358,6 +365,7 @@ void CoreClassFactory1::createClasses(IRuntimeClassRegistrar* registrar) const
classFile->addConstant("FmRead", Any::fromInt32(File::FmRead));
classFile->addConstant("FmWrite", Any::fromInt32(File::FmWrite));
classFile->addConstant("FmAppend", Any::fromInt32(File::FmAppend));
classFile->addConstant("FmMapped", Any::fromInt32(File::FmMapped));
classFile->addConstructor();
classFile->addConstructor< const Path&, uint64_t, uint32_t, const DateTime&, const DateTime&, const DateTime& >();
classFile->addConstructor< const Path&, uint64_t, uint32_t >();
Expand Down Expand Up @@ -454,6 +462,11 @@ void CoreClassFactory1::createClasses(IRuntimeClassRegistrar* registrar) const
classBitWriter->addMethod("tell", &BitWriter::tell);
registrar->registerClass(classBitWriter);

auto classReader = new AutoRuntimeClass< Reader >();
classReader->addConstructor< IStream* >();
classReader->addMethod("readFloat", &Reader_readFloat);
registrar->registerClass(classReader);

auto classFileSystem = new AutoRuntimeClass< FileSystem >();
classFileSystem->addProperty("volumeCount", &FileSystem::getVolumeCount);
classFileSystem->addProperty("currentVolume", &FileSystem::setCurrentVolume, &FileSystem::getCurrentVolume);
Expand Down

0 comments on commit 45908d0

Please sign in to comment.