Fix and improve last PR
Former-commit-id: 16afead68e42411402dfb5a7bd957a4940b6f83a
This commit is contained in:
@@ -14,8 +14,8 @@ namespace Ndk
|
||||
class NDK_API Application
|
||||
{
|
||||
public:
|
||||
Application();
|
||||
~Application();
|
||||
inline Application();
|
||||
inline ~Application();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -24,10 +24,10 @@ namespace Ndk
|
||||
|
||||
static void Register_Audio(Nz::LuaInstance& instance);
|
||||
static void Register_Core(Nz::LuaInstance& instance);
|
||||
static void Register_Math(Nz::LuaInstance& instance);
|
||||
static void Register_Utility(Nz::LuaInstance& instance);
|
||||
static void Register_Graphics(Nz::LuaInstance& instance);
|
||||
static void Register_Math(Nz::LuaInstance& instance);
|
||||
static void Register_Renderer(Nz::LuaInstance& instance);
|
||||
static void Register_Utility(Nz::LuaInstance& instance);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,8 @@ namespace Ndk
|
||||
/*********************************** Nz::SoundBuffer **********************************/
|
||||
Nz::LuaClass<Nz::SoundBufferRef> soundBuffer("SoundBuffer");
|
||||
|
||||
soundBuffer.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::SoundBufferRef* {
|
||||
soundBuffer.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::SoundBufferRef*
|
||||
{
|
||||
return new Nz::SoundBufferRef(new Nz::SoundBuffer);
|
||||
});
|
||||
|
||||
@@ -35,7 +36,7 @@ namespace Ndk
|
||||
|
||||
std::size_t bufferSize = 0;
|
||||
const char* buffer = lua.CheckString(index, &bufferSize);
|
||||
lua.ArgCheck(buffer && bufferSize < sampleCount * sizeof(Nz::Int16), index, "Invalid buffer");
|
||||
lua.ArgCheck(buffer && bufferSize >= sampleCount * sizeof(Nz::Int16), index, "Invalid buffer");
|
||||
|
||||
lua.PushBoolean(instance->Create(format, sampleCount, sampleRate, reinterpret_cast<const Nz::Int16*>(buffer)));
|
||||
return 1;
|
||||
@@ -47,7 +48,8 @@ namespace Ndk
|
||||
return 1;
|
||||
});
|
||||
|
||||
soundBuffer.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& soundBuffer) -> int {
|
||||
soundBuffer.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& soundBuffer) -> int
|
||||
{
|
||||
Nz::StringStream stream("SoundBuffer(");
|
||||
if (soundBuffer->IsValid())
|
||||
{
|
||||
@@ -97,8 +99,8 @@ namespace Ndk
|
||||
Nz::LuaClass<Nz::Sound> soundClass("Sound");
|
||||
soundClass.Inherit(soundEmitter);
|
||||
|
||||
// Constructeur
|
||||
soundClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Sound* {
|
||||
soundClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Sound*
|
||||
{
|
||||
return new Nz::Sound;
|
||||
});
|
||||
|
||||
@@ -108,8 +110,9 @@ namespace Ndk
|
||||
soundClass.SetMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams());
|
||||
soundClass.SetMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset);
|
||||
|
||||
// Nz::Sound::__tostring (Manual)
|
||||
soundClass.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& sound) -> int {
|
||||
// Manual
|
||||
soundClass.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& sound) -> int
|
||||
{
|
||||
Nz::StringStream stream("Sound(");
|
||||
if (const Nz::SoundBuffer* buffer = sound.GetBuffer())
|
||||
stream << buffer;
|
||||
|
||||
@@ -10,76 +10,13 @@ namespace Ndk
|
||||
{
|
||||
void LuaAPI::Register_Core(Nz::LuaInstance& instance)
|
||||
{
|
||||
/******************************** Nz::AbstractHash *******************************/
|
||||
Nz::LuaClass<Nz::AbstractHash> abstractHashClass("AbstractHash");
|
||||
|
||||
abstractHashClass.SetMethod("__tostring",
|
||||
[](Nz::LuaInstance& lua, Nz::AbstractHash& hash) -> int
|
||||
{
|
||||
Nz::StringStream strStrm("Nz::AbstractHash(");
|
||||
|
||||
strStrm << "Hash type: " << hash.GetHashName() << ", ";
|
||||
strStrm << "Digest size: " << hash.GetDigestLength() << ")";
|
||||
|
||||
lua.PushString(strStrm);
|
||||
return 1;
|
||||
});
|
||||
|
||||
abstractHashClass.SetMethod("Append",
|
||||
[](Nz::LuaInstance& lua, Nz::AbstractHash& hash) -> int
|
||||
{
|
||||
size_t dataLength = 0;
|
||||
const Nz::UInt8* data = reinterpret_cast<const Nz::UInt8*>(lua.CheckString(1, &dataLength));
|
||||
|
||||
hash.Append(data, dataLength);
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
abstractHashClass.SetMethod("Begin", &Nz::AbstractHash::Begin);
|
||||
|
||||
abstractHashClass.SetMethod("End",
|
||||
[](Nz::LuaInstance& lua, Nz::AbstractHash& hash) -> int
|
||||
{
|
||||
Nz::ByteArray data(hash.End());
|
||||
|
||||
lua.PushString(data.ToString());
|
||||
return 1;
|
||||
});
|
||||
|
||||
abstractHashClass.SetMethod("GetDigestLength", &Nz::AbstractHash::GetDigestLength);
|
||||
|
||||
abstractHashClass.SetMethod("GetHashName",
|
||||
[](Nz::LuaInstance& lua, Nz::AbstractHash& hash) -> int
|
||||
{
|
||||
Nz::String hashName(hash.GetHashName());
|
||||
lua.PushString(hashName);
|
||||
return 1;
|
||||
});
|
||||
|
||||
abstractHashClass.Register(instance);
|
||||
|
||||
/********************************** Nz::HashMD5 **********************************/
|
||||
Nz::LuaClass<Nz::HashMD5> hashMD5Class("HashMD5");
|
||||
hashMD5Class.Inherit(abstractHashClass);
|
||||
|
||||
hashMD5Class.SetConstructor(
|
||||
[](Nz::LuaInstance& lua) -> Nz::HashMD5*
|
||||
{
|
||||
if(std::min(lua.GetStackTop(), 1U) == 0)
|
||||
return new Nz::HashMD5();
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
hashMD5Class.Register(instance);
|
||||
|
||||
/*********************************** Nz::Clock **********************************/
|
||||
Nz::LuaClass<Nz::Clock> clockClass("Clock");
|
||||
|
||||
// Constructeur
|
||||
clockClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Clock* {
|
||||
int index = 1;
|
||||
return new Nz::Clock(lua.Check<Nz::Int64>(&index, 0), lua.Check<bool>(&index, false));
|
||||
clockClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Clock*
|
||||
{
|
||||
int argIndex = 1;
|
||||
return new Nz::Clock(lua.Check<Nz::Int64>(&argIndex, 0), lua.Check<bool>(&argIndex, false));
|
||||
});
|
||||
|
||||
clockClass.SetMethod("GetMicroseconds", &Nz::Clock::GetMicroseconds);
|
||||
@@ -90,7 +27,7 @@ namespace Ndk
|
||||
clockClass.SetMethod("Restart", &Nz::Clock::Restart);
|
||||
clockClass.SetMethod("Unpause", &Nz::Clock::Unpause);
|
||||
|
||||
// Nz::Clock::__tostring (Manual)
|
||||
// Manual
|
||||
clockClass.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& clock) -> int {
|
||||
Nz::StringStream stream("Clock(Elapsed: ");
|
||||
stream << clock.GetSeconds();
|
||||
@@ -108,21 +45,18 @@ namespace Ndk
|
||||
/********************************* Nz::Directory ********************************/
|
||||
Nz::LuaClass<Nz::Directory> directoryClass("Directory");
|
||||
|
||||
// Constructeur
|
||||
directoryClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Directory* {
|
||||
directoryClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Directory*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 1U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
return new Nz::Directory;
|
||||
}
|
||||
|
||||
case 1:
|
||||
{
|
||||
int index = 1;
|
||||
return new Nz::Directory(lua.Check<Nz::String>(&index));
|
||||
}
|
||||
return new Nz::Directory(lua.Check<Nz::String>(&argIndex));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
@@ -149,7 +83,7 @@ namespace Ndk
|
||||
directoryClass.SetStaticMethod("Remove", Nz::Directory::Remove);
|
||||
directoryClass.SetStaticMethod("SetCurrent", Nz::Directory::SetCurrent);
|
||||
|
||||
// Nz::Directory::__tostring (Manual)
|
||||
// Manual
|
||||
directoryClass.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& directory) -> int {
|
||||
Nz::StringStream stream("Directory(");
|
||||
stream << directory.GetPath();
|
||||
@@ -181,8 +115,9 @@ namespace Ndk
|
||||
streamClass.SetMethod("SetCursorPos", &Nz::Stream::SetCursorPos);
|
||||
|
||||
streamClass.SetMethod("Read", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int {
|
||||
int length = lua.CheckInteger(1);
|
||||
lua.ArgCheck(length > 0, 1, "length must be positive");
|
||||
int argIndex = 1;
|
||||
|
||||
std::size_t length = lua.Check<std::size_t>(&argIndex);
|
||||
|
||||
std::unique_ptr<char[]> buffer(new char[length]);
|
||||
std::size_t readLength = stream.Read(buffer.get(), length);
|
||||
@@ -192,10 +127,10 @@ namespace Ndk
|
||||
});
|
||||
|
||||
streamClass.SetMethod("Write", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int {
|
||||
int index = 1;
|
||||
int argIndex = 1;
|
||||
|
||||
std::size_t bufferSize = 0;
|
||||
const char* buffer = lua.CheckString(index, &bufferSize);
|
||||
const char* buffer = lua.CheckString(argIndex, &bufferSize);
|
||||
|
||||
if (stream.IsTextModeEnabled())
|
||||
lua.Push(stream.Write(Nz::String(buffer, bufferSize)));
|
||||
@@ -210,30 +145,21 @@ namespace Ndk
|
||||
Nz::LuaClass<Nz::File> fileClass("File");
|
||||
fileClass.Inherit(streamClass);
|
||||
|
||||
// Constructeur
|
||||
fileClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::File* {
|
||||
fileClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::File*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
return new Nz::File;
|
||||
}
|
||||
|
||||
case 1:
|
||||
{
|
||||
Nz::String filePath(lua.CheckString(1));
|
||||
|
||||
return new Nz::File(filePath);
|
||||
}
|
||||
return new Nz::File(lua.Check<Nz::String>(&argIndex));
|
||||
|
||||
case 2:
|
||||
{
|
||||
Nz::String filePath(lua.CheckString(1));
|
||||
unsigned long openMode(lua.CheckInteger(2));
|
||||
|
||||
return new Nz::File(filePath, openMode);
|
||||
}
|
||||
return new Nz::File(lua.Check<Nz::String>(&argIndex), lua.Check<Nz::UInt32>(&argIndex));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
@@ -253,80 +179,53 @@ namespace Ndk
|
||||
fileClass.SetMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
||||
fileClass.SetMethod("SetFile", &Nz::File::GetLastWriteTime);
|
||||
|
||||
fileClass.SetMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& file) -> int {
|
||||
fileClass.SetStaticMethod("AbsolutePath", &Nz::File::AbsolutePath);
|
||||
fileClass.SetStaticMethod("ComputeHash", (Nz::ByteArray (*)(Nz::HashType, const Nz::String&)) &Nz::File::ComputeHash);
|
||||
fileClass.SetStaticMethod("Copy", &Nz::File::Copy);
|
||||
fileClass.SetStaticMethod("Delete", &Nz::File::Delete);
|
||||
fileClass.SetStaticMethod("Exists", &Nz::File::Exists);
|
||||
//fileClass.SetStaticMethod("GetCreationTime", &Nz::File::GetCreationTime);
|
||||
fileClass.SetStaticMethod("GetDirectory", &Nz::File::GetDirectory);
|
||||
//fileClass.SetStaticMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime);
|
||||
//fileClass.SetStaticMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
||||
fileClass.SetStaticMethod("GetSize", &Nz::File::GetSize);
|
||||
fileClass.SetStaticMethod("IsAbsolute", &Nz::File::IsAbsolute);
|
||||
fileClass.SetStaticMethod("NormalizePath", &Nz::File::NormalizePath);
|
||||
fileClass.SetStaticMethod("NormalizeSeparators", &Nz::File::NormalizeSeparators);
|
||||
fileClass.SetStaticMethod("Rename", &Nz::File::Rename);
|
||||
|
||||
// Manual
|
||||
fileClass.SetMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& file) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
bool _ret = file.Open();
|
||||
|
||||
lua.PushBoolean(_ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
{
|
||||
unsigned long openMode(lua.ToInteger(1));
|
||||
|
||||
bool _ret = file.Open(openMode);
|
||||
|
||||
lua.PushBoolean(_ret);
|
||||
return 1;
|
||||
}
|
||||
else if (lua.IsOfType(1, Nz::LuaType_String))
|
||||
{
|
||||
Nz::String filePath(lua.ToString(1));
|
||||
|
||||
bool _ret = file.Open(filePath);
|
||||
|
||||
lua.PushBoolean(_ret);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return lua.Push(file.Open(lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen)));
|
||||
|
||||
case 2:
|
||||
{
|
||||
Nz::String filePath(lua.CheckString(1));
|
||||
unsigned long openMode(lua.CheckInteger(2));
|
||||
|
||||
bool _ret = file.Open(filePath, openMode);
|
||||
|
||||
lua.PushBoolean(_ret);
|
||||
return 1;
|
||||
}
|
||||
return lua.Push(file.Open(lua.Check<Nz::String>(&argIndex), lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen)));
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method Open");
|
||||
return 0;
|
||||
});
|
||||
|
||||
fileClass.SetMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& file) -> int {
|
||||
fileClass.SetMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& file) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
Nz::UInt64 offset(lua.CheckInteger(1));
|
||||
|
||||
bool _ret = file.SetCursorPos(offset);
|
||||
|
||||
lua.PushBoolean(_ret);
|
||||
return 1;
|
||||
}
|
||||
return lua.Push(file.SetCursorPos(lua.Check<Nz::UInt64>(&argIndex)));
|
||||
|
||||
case 2:
|
||||
{
|
||||
Nz::CursorPosition pos(static_cast<Nz::CursorPosition>(lua.CheckInteger(1)));
|
||||
Nz::Int64 offset(lua.CheckInteger(2));
|
||||
|
||||
bool _ret = file.SetCursorPos(pos, offset);
|
||||
|
||||
lua.PushBoolean(_ret);
|
||||
return 1;
|
||||
}
|
||||
return lua.Push(file.SetCursorPos(lua.Check<Nz::CursorPosition>(&argIndex), lua.Check<Nz::Int64>(&argIndex)));
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method SetCursorPos");
|
||||
@@ -346,24 +245,47 @@ namespace Ndk
|
||||
|
||||
fileClass.Register(instance);
|
||||
|
||||
// Énumérations de la classe Nz::File
|
||||
fileClass.PushGlobalTable(instance);
|
||||
// Enums
|
||||
|
||||
// Nz::File::CursorPosition
|
||||
instance.SetField("AtBegin", Nz::CursorPosition_AtBegin);
|
||||
instance.SetField("AtCurrent", Nz::CursorPosition_AtCurrent);
|
||||
instance.SetField("AtEnd", Nz::CursorPosition_AtEnd);
|
||||
// Nz::CursorPosition
|
||||
static_assert(Nz::CursorPosition_Max + 1 == 3, "Nz::CursorPosition has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 3);
|
||||
{
|
||||
instance.SetField("AtBegin", Nz::CursorPosition_AtBegin);
|
||||
instance.SetField("AtCurrent", Nz::CursorPosition_AtCurrent);
|
||||
instance.SetField("AtEnd", Nz::CursorPosition_AtEnd);
|
||||
}
|
||||
instance.SetGlobal("CursorPosition");
|
||||
|
||||
// Nz::File::OpenMode
|
||||
instance.SetField("Append", Nz::OpenMode_Append);
|
||||
instance.SetField("NotOpen", Nz::OpenMode_NotOpen);
|
||||
instance.SetField("Lock", Nz::OpenMode_Lock);
|
||||
instance.SetField("ReadOnly", Nz::OpenMode_ReadOnly);
|
||||
instance.SetField("ReadWrite", Nz::OpenMode_ReadWrite);
|
||||
instance.SetField("Text", Nz::OpenMode_Text);
|
||||
instance.SetField("Truncate", Nz::OpenMode_Truncate);
|
||||
instance.SetField("WriteOnly", Nz::OpenMode_WriteOnly);
|
||||
// Nz::HashType
|
||||
static_assert(Nz::HashType_Max + 1 == 9, "Nz::HashType has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 9);
|
||||
{
|
||||
instance.SetField("CRC32", Nz::HashType_CRC32);
|
||||
instance.SetField("Fletcher16", Nz::HashType_Fletcher16);
|
||||
instance.SetField("MD5", Nz::HashType_MD5);
|
||||
instance.SetField("SHA1", Nz::HashType_SHA1);
|
||||
instance.SetField("SHA224", Nz::HashType_SHA224);
|
||||
instance.SetField("SHA256", Nz::HashType_SHA256);
|
||||
instance.SetField("SHA384", Nz::HashType_SHA384);
|
||||
instance.SetField("SHA512", Nz::HashType_SHA512);
|
||||
instance.SetField("Whirlpool", Nz::HashType_Whirlpool);
|
||||
}
|
||||
instance.SetGlobal("HashType");
|
||||
|
||||
instance.Pop();
|
||||
// Nz::OpenMode
|
||||
static_assert(Nz::OpenMode_Max + 1 == 2 * (64), "Nz::OpenModeFlags has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 8);
|
||||
{
|
||||
instance.SetField("Append", Nz::OpenMode_Append);
|
||||
instance.SetField("NotOpen", Nz::OpenMode_NotOpen);
|
||||
instance.SetField("Lock", Nz::OpenMode_Lock);
|
||||
instance.SetField("ReadOnly", Nz::OpenMode_ReadOnly);
|
||||
instance.SetField("ReadWrite", Nz::OpenMode_ReadWrite);
|
||||
instance.SetField("Text", Nz::OpenMode_Text);
|
||||
instance.SetField("Truncate", Nz::OpenMode_Truncate);
|
||||
instance.SetField("WriteOnly", Nz::OpenMode_WriteOnly);
|
||||
}
|
||||
instance.SetGlobal("OpenMode");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,5 @@ namespace Ndk
|
||||
{
|
||||
void LuaAPI::Register_Graphics(Nz::LuaInstance& instance)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -11,115 +11,113 @@ namespace Ndk
|
||||
/*********************************** Nz::Vector2 **********************************/
|
||||
Nz::LuaClass<Nz::Vector2d> vector2dClass("Vector2");
|
||||
|
||||
vector2dClass.SetConstructor(
|
||||
[](Nz::LuaInstance& lua) -> Nz::Vector2d*
|
||||
vector2dClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Vector2d*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
switch (argCount)
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
switch (argCount)
|
||||
case 0:
|
||||
case 2:
|
||||
return new Nz::Vector2d(lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0));
|
||||
|
||||
case 1:
|
||||
{
|
||||
case 0:
|
||||
case 2:
|
||||
return new Nz::Vector2d(lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0));
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
return new Nz::Vector2d(lua.CheckNumber(1));
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
return new Nz::Vector2d(*(*static_cast<Nz::Vector2d*>(lua.ToUserdata(1))));
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
return new Nz::Vector2d(lua.CheckNumber(1));
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
return new Nz::Vector2d(*(*static_cast<Nz::Vector2d*>(lua.ToUserdata(1))));
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for Vector2 constructor");
|
||||
return nullptr;
|
||||
});
|
||||
lua.Error("No matching overload for Vector2 constructor");
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
vector2dClass.SetMethod("__tostring", &Nz::Vector2d::ToString);
|
||||
|
||||
vector2dClass.SetGetter(
|
||||
[](Nz::LuaInstance& lua, Nz::Vector2d& instance)
|
||||
vector2dClass.SetGetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance)
|
||||
{
|
||||
switch (lua.GetType(1))
|
||||
{
|
||||
switch (lua.GetType(1))
|
||||
case Nz::LuaType_Number:
|
||||
lua.Push(instance[lua.CheckInteger(1)]);
|
||||
return true;
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
lua.Push(instance[lua.CheckInteger(1)]);
|
||||
return true;
|
||||
std::size_t length;
|
||||
const char* xy = lua.CheckString(1, &length);
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
std::size_t length;
|
||||
const char* xy = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
break;
|
||||
|
||||
switch (xy[0])
|
||||
{
|
||||
case 'x':
|
||||
lua.Push(instance.x);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.y);
|
||||
return true;
|
||||
}
|
||||
if (length != 1)
|
||||
break;
|
||||
|
||||
switch (xy[0])
|
||||
{
|
||||
case 'x':
|
||||
lua.Push(instance.x);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.y);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
vector2dClass.SetSetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance)
|
||||
{
|
||||
switch (lua.GetType(1))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
long long index = lua.CheckInteger(1);
|
||||
if (index < 1 || index > 2)
|
||||
return false;
|
||||
|
||||
instance[index] = lua.CheckNumber(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
vector2dClass.SetSetter(
|
||||
[](Nz::LuaInstance& lua, Nz::Vector2d& instance)
|
||||
{
|
||||
switch (lua.GetType(1))
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
long long index = lua.CheckInteger(1);
|
||||
if (index < 1 || index > 2)
|
||||
return false;
|
||||
std::size_t length;
|
||||
const char* xy = lua.CheckString(1, &length);
|
||||
|
||||
instance[index] = lua.CheckNumber(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
std::size_t length;
|
||||
const char* xy = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
break;
|
||||
|
||||
double value = lua.CheckNumber(2);
|
||||
|
||||
switch (xy[0])
|
||||
{
|
||||
case 'x':
|
||||
instance.x = value;
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
instance.y = value;
|
||||
return true;
|
||||
}
|
||||
if (length != 1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
double value = lua.CheckNumber(2);
|
||||
|
||||
switch (xy[0])
|
||||
{
|
||||
case 'x':
|
||||
instance.x = value;
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
instance.y = value;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
vector2dClass.Register(instance);
|
||||
|
||||
/*********************************** Nz::Vector3 **********************************/
|
||||
Nz::LuaClass<Nz::Vector3d> vector3dClass("Vector3");
|
||||
|
||||
vector3dClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Vector3d* {
|
||||
vector3dClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Vector3d*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 3U);
|
||||
switch (argCount)
|
||||
{
|
||||
|
||||
@@ -11,138 +11,5 @@ namespace Ndk
|
||||
{
|
||||
void LuaAPI::Register_Renderer(Nz::LuaInstance& instance)
|
||||
{
|
||||
/*********************************** Nz::AbstractImage **********************************/
|
||||
Nz::LuaClass<Nz::AbstractImage*> abstractImage("AbstractImage");
|
||||
|
||||
abstractImage.SetMethod("GetBytesPerPixel", &Nz::AbstractImage::GetBytesPerPixel);
|
||||
abstractImage.SetMethod("GetDepth", &Nz::AbstractImage::GetDepth, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.SetMethod("GetFormat", &Nz::AbstractImage::GetFormat);
|
||||
abstractImage.SetMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.SetMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount);
|
||||
abstractImage.SetMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel);
|
||||
abstractImage.SetMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.SetMethod("GetType", &Nz::AbstractImage::GetType);
|
||||
abstractImage.SetMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.SetMethod("IsCompressed", &Nz::AbstractImage::IsCompressed);
|
||||
abstractImage.SetMethod("IsCubemap", &Nz::AbstractImage::IsCubemap);
|
||||
|
||||
abstractImage.SetMethod("GetMemoryUsage",
|
||||
[](Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int
|
||||
{
|
||||
unsigned int memory = 0;
|
||||
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
if (argCount == 1 && lua.IsOfType(1, Nz::LuaType_Number))
|
||||
memory = abstractImage->GetMemoryUsage(Nz::ranged_cast<Nz::UInt8>(lua.CheckInteger(1)));
|
||||
else
|
||||
memory = abstractImage->GetMemoryUsage();
|
||||
|
||||
lua.PushInteger(memory);
|
||||
return 1;
|
||||
});
|
||||
|
||||
abstractImage.SetMethod("__tostring",
|
||||
[](Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int
|
||||
{
|
||||
lua.PushString(Nz::StringStream("AbstractImage()"));
|
||||
return 1;
|
||||
});
|
||||
|
||||
abstractImage.SetMethod("Update",
|
||||
[](Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
|
||||
if (argCount < 1)
|
||||
{
|
||||
lua.Error("No matching overload for method AbstractImage::Update");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool rValue;
|
||||
const Nz::UInt8* pixels = reinterpret_cast<const Nz::UInt8*>(lua.CheckString(1));
|
||||
|
||||
if (argCount == 1)
|
||||
rValue = abstractImage->Update(pixels);
|
||||
else
|
||||
{
|
||||
// Three possible overloads, based on second argument type
|
||||
if (lua.IsOfType(2, Nz::LuaType_Number)) // Overload #1
|
||||
{
|
||||
/* Prototype is:
|
||||
virtual bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
*/
|
||||
|
||||
unsigned int srcWidth = Nz::ranged_cast<unsigned int>(lua.CheckInteger(2));
|
||||
unsigned int srcHeight = 0;
|
||||
Nz::UInt8 level = 0;
|
||||
|
||||
if (argCount >= 3)
|
||||
{
|
||||
srcHeight = Nz::ranged_cast<unsigned int>(lua.CheckInteger(3));
|
||||
if (argCount >= 4)
|
||||
level = Nz::ranged_cast<Nz::UInt8>(lua.CheckInteger(3));
|
||||
}
|
||||
|
||||
rValue = abstractImage->Update(pixels, srcWidth, srcHeight, level);
|
||||
}
|
||||
else if (lua.IsOfType(2, "Box")) // Overload #2
|
||||
{
|
||||
/* Prototype is:
|
||||
virtual bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
*/
|
||||
|
||||
Nz::Boxui box (*(static_cast<Nz::Boxui*>(lua.ToUserdata(2)))); // Placeholder. Ask Lynix about templates & bindings. Nz::Box<T> has to be bound, too.
|
||||
unsigned int srcWidth = 0;
|
||||
unsigned int srcHeight = 0;
|
||||
Nz::UInt8 level = 0;
|
||||
|
||||
if (argCount >= 3)
|
||||
{
|
||||
srcWidth = Nz::ranged_cast<unsigned int>(lua.CheckInteger(3));
|
||||
if (argCount >= 4)
|
||||
{
|
||||
srcHeight = Nz::ranged_cast<unsigned int>(lua.CheckInteger(4));
|
||||
if (argCount >= 5)
|
||||
level = Nz::ranged_cast<Nz::UInt8>(lua.CheckInteger(5));
|
||||
}
|
||||
}
|
||||
rValue = abstractImage->Update(pixels, box, srcWidth, srcHeight, level);
|
||||
}
|
||||
else if (lua.IsOfType(2, "Rect")) // Overload #3
|
||||
{
|
||||
/* Prototype is:
|
||||
virtual bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
*/
|
||||
|
||||
Nz::Rectui rect(*(static_cast<Nz::Rectui*>(lua.ToUserdata(2)))); // Placeholder. See comment at box declaration in overload #2
|
||||
unsigned int z = 0;
|
||||
unsigned int srcWidth = 0;
|
||||
unsigned int srcHeight = 0;
|
||||
Nz::UInt8 level = 0;
|
||||
|
||||
if (argCount >= 3)
|
||||
{
|
||||
z = Nz::ranged_cast<unsigned int>(lua.CheckInteger(3));
|
||||
if (argCount >= 4)
|
||||
{
|
||||
srcWidth = Nz::ranged_cast<unsigned int>(lua.CheckInteger(4));
|
||||
if (argCount >= 5)
|
||||
{
|
||||
srcHeight = Nz::ranged_cast<unsigned int>(lua.CheckInteger(5));
|
||||
if (argCount >= 6)
|
||||
level = Nz::ranged_cast<Nz::UInt8>(lua.CheckInteger(6));
|
||||
}
|
||||
}
|
||||
}
|
||||
rValue = abstractImage->Update(pixels, rect, z, srcWidth, srcHeight, level);
|
||||
}
|
||||
}
|
||||
|
||||
lua.PushBoolean(rValue);
|
||||
return 1;
|
||||
});
|
||||
|
||||
abstractImage.Register(instance);
|
||||
}
|
||||
}
|
||||
@@ -10,5 +10,88 @@ namespace Ndk
|
||||
{
|
||||
void LuaAPI::Register_Utility(Nz::LuaInstance& instance)
|
||||
{
|
||||
/*********************************** Nz::AbstractImage **********************************/
|
||||
Nz::LuaClass<Nz::AbstractImage*> abstractImage("AbstractImage");
|
||||
|
||||
abstractImage.SetMethod("GetBytesPerPixel", &Nz::AbstractImage::GetBytesPerPixel);
|
||||
abstractImage.SetMethod("GetDepth", &Nz::AbstractImage::GetDepth, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.SetMethod("GetFormat", &Nz::AbstractImage::GetFormat);
|
||||
abstractImage.SetMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.SetMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount);
|
||||
abstractImage.SetMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel);
|
||||
abstractImage.SetMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.SetMethod("GetType", &Nz::AbstractImage::GetType);
|
||||
abstractImage.SetMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.SetMethod("IsCompressed", &Nz::AbstractImage::IsCompressed);
|
||||
abstractImage.SetMethod("IsCubemap", &Nz::AbstractImage::IsCubemap);
|
||||
|
||||
abstractImage.SetMethod("GetMemoryUsage", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 1U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return lua.Push(abstractImage->GetMemoryUsage());
|
||||
|
||||
case 1:
|
||||
{
|
||||
int index = 1;
|
||||
Nz::UInt8 level(lua.Check<Nz::UInt8>(&index));
|
||||
|
||||
return lua.Push(abstractImage->GetMemoryUsage(level));
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method GetMemoryUsage");
|
||||
return 0;
|
||||
});
|
||||
|
||||
abstractImage.SetMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 6U);
|
||||
int argIndex = 1;
|
||||
|
||||
std::size_t bufferSize = 0;
|
||||
const Nz::UInt8* pixels = reinterpret_cast<const Nz::UInt8*>(lua.CheckString(argIndex++, &bufferSize));
|
||||
|
||||
if (argCount < 2 || lua.IsOfType(2, Nz::LuaType_Number))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}
|
||||
/* Disabled until Box and Rect have been ported
|
||||
else if (lua.IsOfType(2, "Box"))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
Nz::Boxui box = lua.Check<Nz::Boxui>(&argIndex);
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}
|
||||
else if (lua.IsOfType(2, "Rect"))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
Nz::Rectui box = lua.Check<Nz::Rectui>(&argIndex);
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}*/
|
||||
|
||||
lua.Error("No matching overload for method Update");
|
||||
return 0;
|
||||
});
|
||||
|
||||
abstractImage.Register(instance);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user