Fix and improve last PR

Former-commit-id: 16afead68e42411402dfb5a7bd957a4940b6f83a
This commit is contained in:
Lynix 2016-01-24 15:20:14 +01:00
parent a32a1d428f
commit d7ab29e5ef
14 changed files with 325 additions and 1279 deletions

6
.gitignore vendored
View File

@ -1,6 +1,8 @@
# Nazara build
examples/bin/*.exe
examples/bin/*.pdb
tests/*.exe
tests/*.pdb
lib/*
# Feature page
@ -22,6 +24,7 @@ build/**/*.workspace
build/**/*.project
# Visual Studio
build/**/*.pdb
build/**/*.filters
build/**/*.vcxproj
build/**/*.tlog
@ -30,7 +33,6 @@ build/**/*.vcxprojResolveAssemblyReference.cache
build/**/*.nativecodeanalysis.all.xml
build/**/*.nativecodeanalysis.xml
build/**/*.VC.opendb
lib/*.exp
# Compiled Object files
build/**/*.slo
@ -40,7 +42,6 @@ build/**/*.obj
# Compiled Dynamic libraries
build/**/*.so
lib/*.lib
# Compiled Static libraries
build/**/*.lai
@ -75,7 +76,6 @@ $RECYCLE.BIN/
*.ilk
*.meta
*.pch
*.pdb
*.pgc
*.pgd
*.rsp

View File

@ -14,8 +14,8 @@ namespace Ndk
class NDK_API Application
{
public:
Application();
~Application();
inline Application();
inline ~Application();
};
}

View File

@ -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);
};
}

View File

@ -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;

View File

@ -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");
}
}

View File

@ -10,6 +10,5 @@ namespace Ndk
{
void LuaAPI::Register_Graphics(Nz::LuaInstance& instance)
{
}
}

View File

@ -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)
{

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -1 +1 @@
premake5 --united --with-extlibs --with-examples codeblocks
premake4 --united --with-extlibs --with-examples codeblocks

View File

@ -9,7 +9,7 @@ function NazaraBuild:Execute()
local makeLibDir = os.is("windows") and "mingw" or "gmake"
if (#self.OrderedExtLibs > 0) then
solution("NazaraExtlibs")
workspace("NazaraExtlibs")
platforms({"x32", "x64"})
-- Configuration générale
@ -60,7 +60,10 @@ function NazaraBuild:Execute()
flags("Symbols")
configuration("Release*")
flags({"EnableSSE2", "Optimize", "OptimizeSpeed", "NoFramePointer", "NoRTTI"})
flags("NoFramePointer")
optimize("Speed")
rtti("Off")
vectorextensions("SSE2")
configuration({"Release*", "codeblocks or codelite or gmake or xcode3 or xcode4"})
buildoptions("-mfpmath=sse") -- Utilisation du SSE pour les calculs flottants
@ -98,7 +101,7 @@ function NazaraBuild:Execute()
end
end
solution("NazaraEngine")
workspace("NazaraEngine")
platforms({"x32", "x64"})
-- Configuration générale
@ -117,7 +120,10 @@ function NazaraBuild:Execute()
flags("Symbols")
configuration("Release*")
flags({"EnableSSE2", "Optimize", "OptimizeSpeed", "NoFramePointer", "NoRTTI"})
flags("NoFramePointer")
optimize("Speed")
rtti("Off")
vectorextensions("SSE2")
configuration({"Release*", "codeblocks or codelite or gmake or xcode3 or xcode4"})
buildoptions("-mfpmath=sse") -- Utilisation du SSE pour les calculs flottants

View File

@ -1,839 +0,0 @@
NazaraBuild = {} -- L'équivalent d'un namespace en Lua est une table
function NazaraBuild:Execute()
if (_ACTION == nil) then -- Si aucune action n'est spécifiée
return -- Alors l'utilisateur voulait probablement savoir comment utiliser le programme, on ne fait rien
end
if (self.Actions[_ACTION] == nil) then
local makeLibDir = os.is("windows") and "mingw" or "gmake"
if (#self.OrderedExtLibs > 0) then
solution("NazaraExtlibs")
platforms({"x32", "x64"})
-- Configuration générale
configurations({
"DebugStatic",
"ReleaseStatic"
})
includedirs("../extlibs/include")
libdirs("../extlibs/lib/common")
location(_ACTION)
kind("StaticLib")
configuration("x32")
libdirs("../extlibs/lib/common/x86")
configuration("x64")
libdirs("../extlibs/lib/common/x64")
configuration({"codeblocks or codelite or gmake", "x32"})
libdirs("../extlibs/lib/" .. makeLibDir .. "/x86")
targetdir("../extlibs/lib/" .. makeLibDir .. "/x86")
configuration({"codeblocks or codelite or gmake", "x64"})
libdirs("../extlibs/lib/" .. makeLibDir .. "/x64")
targetdir("../extlibs/lib/" .. makeLibDir .. "/x64")
configuration("vs*")
buildoptions("/MP")
configuration({"vs*", "x32"})
libdirs("../extlibs/lib/msvc/x86")
targetdir("../extlibs/lib/msvc/x86")
configuration({"vs*", "x64"})
libdirs("../extlibs/lib/msvc/x64")
targetdir("../extlibs/lib/msvc/x64")
configuration({"xcode3 or xcode4", "x32"})
libdirs("../extlibs/lib/xcode/x86")
targetdir("../extlibs/lib/xcode/x86")
configuration({"xcode3 or xcode4", "x64"})
libdirs("../extlibs/lib/xcode/x64")
targetdir("../extlibs/lib/xcode/x64")
configuration("Debug*")
flags("Symbols")
configuration("Release*")
flags({"EnableSSE2", "Optimize", "OptimizeSpeed", "NoFramePointer"})
rtti("Off")
configuration({"Release*", "codeblocks or codelite or gmake or xcode3 or xcode4"})
buildoptions("-mfpmath=sse") -- Utilisation du SSE pour les calculs flottants
buildoptions("-ftree-vectorize") -- Activation de la vectorisation du code
configuration("DebugStatic")
targetsuffix("-s-d")
configuration("ReleaseStatic")
targetsuffix("-s")
configuration("codeblocks or codelite or gmake or xcode3 or xcode4")
buildoptions({"-fPIC", "-std=c++14"})
for k, libTable in ipairs(self.OrderedExtLibs) do
project(libTable.Name)
language(libTable.Language)
location(_ACTION .. "/extlibs")
files(libTable.Files)
excludes(libTable.FilesExclusion)
defines(libTable.Defines)
flags(libTable.Flags)
includedirs(libTable.Includes)
links(libTable.Libraries)
for k,v in pairs(libTable.ConfigurationLibraries) do
configuration(k)
links(v)
end
configuration({})
end
end
solution("NazaraEngine")
platforms({"x32", "x64"})
-- Configuration générale
configurations({
-- "DebugStatic",
-- "ReleaseStatic",
"DebugDynamic",
"ReleaseDynamic"
})
language("C++")
location(_ACTION)
configuration("Debug*")
defines("NAZARA_DEBUG")
flags("Symbols")
configuration("Release*")
flags({"EnableSSE2", "Optimize", "OptimizeSpeed", "NoFramePointer"})
rtti("Off")
configuration({"Release*", "codeblocks or codelite or gmake or xcode3 or xcode4"})
buildoptions("-mfpmath=sse") -- Utilisation du SSE pour les calculs flottants
buildoptions("-ftree-vectorize") -- Activation de la vectorisation du code
configuration("*Static")
defines("NAZARA_STATIC")
configuration("codeblocks or codelite or gmake or xcode3 or xcode4")
buildoptions("-std=c++14")
configuration({"linux or bsd or macosx", "gmake"})
buildoptions("-fvisibility=hidden")
configuration({"linux or bsd or macosx", "gmake"})
buildoptions("-fvisibility=hidden")
configuration("vs*")
buildoptions("/MP") -- Multiprocessus build
flags("NoMinimalRebuild")
defines("_CRT_SECURE_NO_WARNINGS")
defines("_SCL_SECURE_NO_WARNINGS")
-- Spécification des modules
if (_OPTIONS["united"]) then
project("NazaraEngine")
end
for k, moduleTable in ipairs(self.OrderedModules) do
if (not _OPTIONS["united"]) then
project("Nazara" .. moduleTable.Name)
end
location(_ACTION .. "/modules")
defines("NAZARA_BUILD")
includedirs({
"../include",
"../src/",
"../extlibs/include"
})
libdirs("../lib")
libdirs("../extlibs/lib/common")
configuration("x32")
libdirs("../extlibs/lib/common/x86")
configuration("x64")
defines("NAZARA_PLATFORM_x64")
libdirs("../extlibs/lib/common/x64")
configuration({"codeblocks or codelite or gmake", "x32"})
libdirs("../extlibs/lib/" .. makeLibDir .. "/x86")
libdirs("../lib/" .. makeLibDir .. "/x86")
targetdir("../lib/" .. makeLibDir .. "/x86")
configuration({"codeblocks or codelite or gmake", "x64"})
libdirs("../extlibs/lib/" .. makeLibDir .. "/x64")
libdirs("../lib/" .. makeLibDir .. "/x64")
targetdir("../lib/" .. makeLibDir .. "/x64")
configuration({"vs*", "x32"})
libdirs("../extlibs/lib/msvc/x86")
libdirs("../lib/msvc/x86")
targetdir("../lib/msvc/x86")
configuration({"vs*", "x64"})
libdirs("../extlibs/lib/msvc/x64")
libdirs("../lib/msvc/x64")
targetdir("../lib/msvc/x64")
configuration({"xcode3 or xcode4", "x32"})
libdirs("../extlibs/lib/xcode/x86")
libdirs("../lib/xcode/x86")
targetdir("../lib/xcode/x86")
configuration({"xcode3 or xcode4", "x64"})
libdirs("../extlibs/lib/xcode/x64")
libdirs("../lib/xcode/x64")
targetdir("../lib/xcode/x64")
configuration("*Static")
kind("StaticLib")
configuration("*Dynamic")
kind("SharedLib")
configuration("DebugStatic")
targetsuffix("-s-d")
configuration("ReleaseStatic")
targetsuffix("-s")
configuration("DebugDynamic")
targetsuffix("-d")
configuration({})
files(moduleTable.Files)
excludes(moduleTable.FilesExclusion)
defines(moduleTable.Defines)
flags(moduleTable.Flags)
includedirs(moduleTable.Includes)
links(moduleTable.Libraries)
for k,v in pairs(moduleTable.ConfigurationLibraries) do
configuration(k)
links(v)
end
configuration({})
end
-- Tools
for k, toolTable in ipairs(self.OrderedTools) do
project("Nazara" .. toolTable.Name)
location(_ACTION .. "/tools")
targetdir(toolTable.Directory)
if (toolTable.Kind == "library") then
kind("SharedLib")
elseif (toolTable.Kind == "consoleapp") then
debugdir(toolTable.Directory)
kind("ConsoleApp")
elseif (toolTable.Kind == "windowapp") then
debugdir(toolTable.Directory)
kind("WindowedApp")
else
assert(false, "wut")
end
includedirs({
"../include",
"../extlibs/include"
})
libdirs("../lib")
libdirs("../extlibs/lib/common")
configuration("x32")
libdirs("../extlibs/lib/common/x86")
configuration("x64")
defines("NAZARA_PLATFORM_x64")
libdirs("../extlibs/lib/common/x64")
configuration({"codeblocks or codelite or gmake", "x32"})
libdirs("../extlibs/lib/" .. makeLibDir .. "/x86")
libdirs("../lib/" .. makeLibDir .. "/x86")
if (toolTable.Kind == "library") then
targetdir("../lib/" .. makeLibDir .. "/x86")
end
configuration({"codeblocks or codelite or gmake", "x64"})
libdirs("../extlibs/lib/" .. makeLibDir .. "/x64")
libdirs("../lib/" .. makeLibDir .. "/x64")
if (toolTable.Kind == "library") then
targetdir("../lib/" .. makeLibDir .. "/x64")
end
configuration({"vs*", "x32"})
libdirs("../extlibs/lib/msvc/x86")
libdirs("../lib/msvc/x86")
if (toolTable.Kind == "library") then
targetdir("../lib/msvc/x86")
end
configuration({"vs*", "x64"})
libdirs("../extlibs/lib/msvc/x64")
libdirs("../lib/msvc/x64")
if (toolTable.Kind == "library") then
targetdir("../lib/msvc/x64")
end
configuration({"xcode3 or xcode4", "x32"})
libdirs("../extlibs/lib/xcode/x86")
libdirs("../lib/xcode/x86")
if (toolTable.Kind == "library") then
targetdir("../lib/xcode/x86")
end
configuration({"xcode3 or xcode4", "x64"})
libdirs("../extlibs/lib/xcode/x64")
libdirs("../lib/xcode/x64")
if (toolTable.Kind == "library") then
targetdir("../lib/xcode/x64")
end
if (toolTable.Kind == "library") then
configuration("*Static")
kind("StaticLib")
configuration("*Dynamic")
kind("SharedLib")
configuration("DebugStatic")
targetsuffix("-s-d")
configuration("ReleaseStatic")
targetsuffix("-s")
configuration("DebugDynamic")
targetsuffix("-d")
end
configuration({})
files(toolTable.Files)
excludes(toolTable.FilesExclusion)
defines(toolTable.Defines)
flags(toolTable.Flags)
includedirs(toolTable.Includes)
links(toolTable.Libraries)
for k,v in pairs(toolTable.ConfigurationLibraries) do
configuration(k)
links(v)
end
configuration({})
end
for k, exampleTable in ipairs(self.OrderedExamples) do
project("Demo" .. exampleTable.Name)
location(_ACTION .. "/examples")
if (exampleTable.Console) then
kind("ConsoleApp")
else
kind("Window")
end
debugdir("../examples/bin")
includedirs({
"../include",
"../extlibs/include"
})
libdirs("../lib")
targetdir("../examples/bin")
files(exampleTable.Files)
excludes(exampleTable.FilesExclusion)
defines(exampleTable.Defines)
flags(exampleTable.Flags)
includedirs(exampleTable.Includes)
links(exampleTable.Libraries)
configuration("x32")
libdirs("../extlibs/lib/common/x86")
configuration("x64")
defines("NAZARA_PLATFORM_x64")
libdirs("../extlibs/lib/common/x64")
configuration({"codeblocks or codelite or gmake", "x32"})
libdirs("../lib/" .. makeLibDir .. "/x86")
configuration({"codeblocks or codelite or gmake", "x64"})
libdirs("../lib/" .. makeLibDir .. "/x64")
configuration({"vs*", "x32"})
libdirs("../lib/msvc/x86")
configuration({"vs*", "x64"})
libdirs("../lib/msvc/x64")
configuration({"xcode3 or xcode4", "x32"})
libdirs("../lib/xcode/x86")
configuration({"xcode3 or xcode4", "x64"})
libdirs("../lib/xcode/x64")
for k,v in pairs(exampleTable.ConfigurationLibraries) do
configuration(k)
links(v)
end
configuration({})
end
end
end
function NazaraBuild:Initialize()
-- Commençons par les options
newoption({
trigger = "united",
description = "Builds all the modules as one united library"
})
newoption({
trigger = "with-extlibs",
description = "Builds the extern libraries"
})
newoption({
trigger = "with-examples",
description = "Builds the examples"
})
self.Actions = {}
self.Examples = {}
self.ExtLibs = {}
self.Modules = {}
self.Tools = {}
-- Actions
modules = os.matchfiles("scripts/actions/*.lua")
for k,v in pairs(modules) do
local f, err = loadfile(v)
if (f) then
ACTION = {}
f()
local succeed, err = self:RegisterAction(ACTION)
if (not succeed) then
print("Unable to register action: " .. err)
end
else
print("Unable to load action file: " .. err)
end
end
ACTION = nil
-- Extern libraries
if (_OPTIONS["with-extlibs"]) then
local extlibs = os.matchfiles("../extlibs/build/*.lua")
for k,v in pairs(extlibs) do
local f, err = loadfile(v)
if (f) then
LIBRARY = {}
self:SetupInfoTable(LIBRARY)
f()
local succeed, err = self:RegisterExternLibrary(LIBRARY)
if (not succeed) then
print("Unable to register extern library: " .. err)
end
else
print("Unable to load extern library file: " .. err)
end
end
LIBRARY = nil
end
-- Then the modules
local modules = os.matchfiles("scripts/modules/*.lua")
for k,v in pairs(modules) do
local moduleName = v:match(".*/(.*).lua")
local moduleNameLower = moduleName:lower()
if (moduleNameLower ~= "core") then -- exclure le noyau n'aurait aucun sens
newoption({
trigger = "exclude-" .. moduleNameLower,
description = "Exclude the " .. moduleName .. " module from the build system"
})
end
if (not _OPTIONS["exclude-" .. moduleNameLower]) then
local f, err = loadfile(v)
if (f) then
MODULE = {}
self:SetupInfoTable(MODULE)
f()
local succeed, err = self:RegisterModule(MODULE)
if (not succeed) then
print("Unable to register module: " .. err)
end
else
print("Unable to load module file: " .. err)
end
end
end
MODULE = nil
-- Continue with the tools (ex: SDK)
local tools = os.matchfiles("scripts/tools/*.lua")
for k,v in pairs(tools) do
local toolName = v:match(".*/(.*).lua")
local toolNameLower = toolName:lower()
newoption({
trigger = "exclude-" .. toolNameLower,
description = "Exclude the " .. toolName .. " tool from the build system"
})
if (not _OPTIONS["exclude-" .. toolNameLower]) then
local f, err = loadfile(v)
if (f) then
TOOL = {}
self:SetupInfoTable(TOOL)
f()
local succeed, err = self:RegisterTool(TOOL)
if (not succeed) then
print("Unable to register tool: " .. err)
end
else
print("Unable to load tool file: " .. err)
end
end
end
TOOL = nil
-- Examples
if (_OPTIONS["with-examples"]) then
local examples = os.matchdirs("../examples/*")
for k,v in pairs(examples) do
local dirName = v:match(".*/(.*)")
if (dirName ~= "bin" and dirName ~= "build") then
local f, err = loadfile(v .. "/build.lua")
if (f) then
EXAMPLE = {}
EXAMPLE.Directory = dirName
self:SetupInfoTable(EXAMPLE)
f()
local succeed, err = self:RegisterExample(EXAMPLE)
if (not succeed) then
print("Unable to register example: " .. err)
end
else
print("Unable to load example file: " .. err)
end
end
end
EXAMPLE = nil
end
-- Once everything is registred, let's process all the tables
self.OrderedExamples = {}
self.OrderedExtLibs = {}
self.OrderedModules = {}
self.OrderedTools = {}
local tables = {self.Examples, self.ExtLibs, self.Modules, self.Tools}
local orderedTables = {self.OrderedExamples, self.OrderedExtLibs, self.OrderedModules, self.OrderedTools}
for k,projects in ipairs(tables) do
for projectId,projectTable in pairs(projects) do
self:Process(projectTable)
table.insert(orderedTables[k], projectTable)
end
table.sort(orderedTables[k], function (a, b) return a.Name < b.Name end)
end
end
function NazaraBuild:RegisterAction(actionTable)
if (actionTable.Name == nil or type(actionTable.Name) ~= "string" or string.len(actionTable.Name) == 0) then
return false, "Invalid action name"
end
local lowerCaseName = string.lower(actionTable.Name)
if (self.Actions[lowerCaseName] ~= nil) then
return false, "This action name is already in use"
end
if (actionTable.Description == nil or type(actionTable.Description) ~= "string") then
return false, "Action description is invalid"
end
if (string.len(actionTable.Description) == 0) then
return false, "Action description is empty"
end
if (self.Actions[actionTable.name] ~= nil) then
return false, "Action name \"" .. actionTable.name .. " is already registred"
end
if (actionTable.Function == nil or type(actionTable.Function) ~= "function") then
return false, "Action function is invalid"
end
self.Actions[lowerCaseName] = actionTable
newaction
{
trigger = lowerCaseName,
description = actionTable.Description,
execute = function () actionTable:Function() end
}
return true
end
function NazaraBuild:RegisterExample(exampleTable)
if (exampleTable.Name == nil or type(exampleTable.Name) ~= "string" or string.len(exampleTable.Name) == 0) then
return false, "Invalid example name"
end
local lowerCaseName = exampleTable.Name:lower()
if (self.Examples[lowerCaseName] ~= nil) then
return false, "This library name is already in use"
end
if (exampleTable.Files == nil or type(exampleTable.Files) ~= "table") then
return false, "Example files table is invalid"
end
if (#exampleTable.Files == 0) then
return false, "This example has no files"
end
local files = {}
for k, file in ipairs(exampleTable.Files) do
table.insert(files, "../examples/" .. exampleTable.Directory .. "/" .. file)
end
exampleTable.Files = files
exampleTable.Type = "Example"
self.Examples[lowerCaseName] = exampleTable
return true
end
function NazaraBuild:RegisterExternLibrary(libTable)
if (libTable.Name == nil or type(libTable.Name) ~= "string" or string.len(libTable.Name) == 0) then
return false, "Invalid library name"
end
local lowerCaseName = libTable.Name:lower()
if (self.ExtLibs[lowerCaseName] ~= nil) then
return false, "This library name is already in use"
end
if (libTable.Files == nil or type(libTable.Files) ~= "table") then
return false, "Invalid file table"
end
if (#libTable.Files == 0) then
return false, "This library has no files"
end
libTable.Type = "ExternLib"
self.ExtLibs[lowerCaseName] = libTable
return true
end
function NazaraBuild:RegisterModule(moduleTable)
if (moduleTable.Name == nil or type(moduleTable.Name) ~= "string" or string.len(moduleTable.Name) == 0) then
return false, "Invalid module name"
end
local lowerCaseName = moduleTable.Name:lower()
if (self.Modules[lowerCaseName] ~= nil) then
return false, "This module name is already in use"
end
table.insert(moduleTable.Defines, "NAZARA_" .. moduleTable.Name:upper() .. "_BUILD")
table.insert(moduleTable.Files, "../include/Nazara/" .. moduleTable.Name .. "/**.hpp")
table.insert(moduleTable.Files, "../include/Nazara/" .. moduleTable.Name .. "/**.inl")
table.insert(moduleTable.Files, "../src/Nazara/" .. moduleTable.Name .. "/**.hpp")
table.insert(moduleTable.Files, "../src/Nazara/" .. moduleTable.Name .. "/**.inl")
table.insert(moduleTable.Files, "../src/Nazara/" .. moduleTable.Name .. "/**.cpp")
if (_OPTIONS["united"] and lowerCaseName ~= "core") then
table.insert(moduleTable.FilesExclusion, "../src/Nazara/" .. moduleTable.Name .. "/Debug/NewOverload.cpp")
end
moduleTable.Type = "Module"
self.Modules[lowerCaseName] = moduleTable
return true
end
function NazaraBuild:RegisterTool(toolTable)
if (toolTable.Name == nil or type(toolTable.Name) ~= "string" or string.len(toolTable.Name) == 0) then
return false, "Invalid tool name"
end
local lowerCaseName = toolTable.Name:lower()
if (self.Tools[lowerCaseName] ~= nil) then
return false, "This tool name is already in use"
end
if (toolTable.Directory == nil or type(toolTable.Directory) ~= "string" or string.len(toolTable.Directory) == 0) then
return false, "Invalid tool directory"
end
if (toolTable.Kind == nil or type(toolTable.Kind) ~= "string" or string.len(toolTable.Kind) == 0) then
return false, "Invalid tool type"
end
local lowerCaseKind = toolTable.Kind:lower()
if (lowerCaseKind == "library" or lowerCaseKind == "consoleapp" or lowerCaseKind == "windowapp") then
toolTable.Kind = lowerCaseKind
else
return false, "Invalid tool type"
end
toolTable.Type = "Tool"
self.Tools[lowerCaseName] = toolTable
return true
end
local PosixOSes = {
["bsd"] = true,
["linux"] = true,
["macosx"] = true,
["solaris"] = true
}
function NazaraBuild:Process(infoTable)
local libraries = {}
for k, library in pairs(infoTable.Libraries) do
local moduleName = library:match("Nazara(%w+)")
local moduleTable = moduleName and self.Modules[moduleName:lower()]
local toolTable = moduleName and self.Tools[moduleName:lower()]
if (moduleTable) then
if (_OPTIONS["united"]) then
library = "NazaraEngine"
else
library = "Nazara" .. moduleTable.Name
end
if (not _OPTIONS["united"] or infoTable.Type ~= "Module") then
table.insert(infoTable.ConfigurationLibraries.DebugStatic, library .. "-s-d")
table.insert(infoTable.ConfigurationLibraries.ReleaseStatic, library .. "-s")
table.insert(infoTable.ConfigurationLibraries.DebugDynamic, library .. "-d")
table.insert(infoTable.ConfigurationLibraries.ReleaseDynamic, library)
end
else
local extLibTable = self.ExtLibs[library:lower()]
if (extLibTable) then
library = extLibTable.Name
table.insert(infoTable.ConfigurationLibraries.DebugStatic, library .. "-s-d")
table.insert(infoTable.ConfigurationLibraries.ReleaseStatic, library .. "-s")
table.insert(infoTable.ConfigurationLibraries.DebugDynamic, library .. "-s-d")
table.insert(infoTable.ConfigurationLibraries.ReleaseDynamic, library .. "-s")
else
if (toolTable and toolTable.Kind == "library") then
library = "Nazara" .. toolTable.Name
-- Import tools includes
for k,v in ipairs(toolTable.Includes) do
table.insert(infoTable.Includes, v)
end
table.insert(infoTable.ConfigurationLibraries.DebugStatic, library .. "-s-d")
table.insert(infoTable.ConfigurationLibraries.ReleaseStatic, library .. "-s")
table.insert(infoTable.ConfigurationLibraries.DebugDynamic, library .. "-d")
table.insert(infoTable.ConfigurationLibraries.ReleaseDynamic, library)
else
table.insert(libraries, library)
end
end
end
end
infoTable.Libraries = libraries
for platform, fileTable in pairs(infoTable.OsFiles) do
platform = string.lower(platform)
if (platform == "posix") then
local osname = os.get()
if (PosixOSes[osname]) then
platform = osname
end
end
if (os.is(platform)) then
for k,v in ipairs(fileTable) do
table.insert(infoTable.Files, v)
end
else
for k,v in ipairs(fileTable) do
table.insert(infoTable.FilesExclusion, v)
end
end
end
infoTable.OsFiles = nil
for platform, libraryTable in pairs(infoTable.OsLibraries) do
platform = string.lower(platform)
if (platform == "posix") then
local osname = os.get()
if (PosixOSes[osname]) then
platform = osname
end
end
if (os.is(platform)) then
for k,v in ipairs(libraryTable) do
table.insert(infoTable.Libraries, v)
end
end
end
infoTable.OsLibraries = nil
end
function NazaraBuild:SetupInfoTable(infoTable)
infoTable.ConfigurationLibraries = {}
infoTable.ConfigurationLibraries.DebugStatic = {}
infoTable.ConfigurationLibraries.ReleaseStatic = {}
infoTable.ConfigurationLibraries.DebugDynamic = {}
infoTable.ConfigurationLibraries.ReleaseDynamic = {}
infoTable.Defines = {}
infoTable.Files = {}
infoTable.FilesExclusion = {}
infoTable.Flags = {}
infoTable.Includes = {}
infoTable.Libraries = {}
infoTable.OsFiles = {}
infoTable.OsLibraries = {}
end

View File

@ -15,7 +15,6 @@
#include <Nazara/Lua/Enums.hpp>
#include <cstddef>
#include <functional>
#include <limits>
struct lua_Debug;
struct lua_State;
@ -48,6 +47,8 @@ namespace Nz
void CheckAny(int index) const;
bool CheckBoolean(int index) const;
bool CheckBoolean(int index, bool defValue) const;
template<typename T> T CheckBoundInteger(int index) const;
template<typename T> T CheckBoundInteger(int index, T defValue) const;
template<typename T> T CheckField(const char* fieldName, int tableIndex = -1) const;
template<typename T> T CheckField(const String& fieldName, int tableIndex = -1) const;
template<typename T> T CheckField(const char* fieldName, T defValue, int tableIndex = -1) const;
@ -176,6 +177,7 @@ namespace Nz
static LuaInstance* GetInstance(lua_State* state);
private:
template<typename T> T CheckBounds(int index, long long value) const;
bool Run(int argCount, int resultCount);
static void* MemoryAllocator(void *ud, void *ptr, std::size_t osize, std::size_t nsize);
@ -190,14 +192,6 @@ namespace Nz
lua_State* m_state;
unsigned int m_level;
};
// Performs a 'ranged cast' to type T, i.e. a cast guaranteed to end up within the numerical limits of the type (or the limits provided in argument),
// without over- or under-flowing.
// Values beyond that range will be truncated to the type minimum (resp. maximum) if they are greater (resp. lesser) than the initial value.
template <class T> T ranged_cast(long long a, T high = std::numeric_limits<T>::max(), T low = std::numeric_limits<T>::min())
{
return static_cast<T>(std::min(static_cast<long long>(high), std::max(a, static_cast<long long>(low))));
}
}
#include <Nazara/Lua/LuaInstance.inl>

View File

@ -3,8 +3,10 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Algorithm.hpp>
#include <limits>
#include <string>
#include <type_traits>
#include "LuaInstance.hpp"
namespace Nz
{
@ -70,33 +72,19 @@ namespace Nz
}
template<typename T>
std::enable_if_t<std::is_integral<T>::value && !std::is_unsigned<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
std::enable_if_t<std::is_integral<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
{
*arg = static_cast<T>(instance.CheckInteger(index));
*arg = instance.CheckBoundInteger<T>(index);
return 1;
}
template<typename T>
std::enable_if_t<std::is_integral<T>::value && !std::is_unsigned<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
std::enable_if_t<std::is_integral<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
{
*arg = static_cast<T>(instance.CheckInteger(index, defValue));
*arg = instance.CheckBoundInteger<T>(index, defValue);
return 1;
}
template<typename T>
std::enable_if_t<std::is_unsigned<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
{
using SignedT = std::make_signed_t<T>;
return LuaImplQueryArg(instance, index, reinterpret_cast<SignedT*>(arg), TypeTag<SignedT>());
}
template<typename T>
std::enable_if_t<std::is_unsigned<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
{
using SignedT = std::make_signed_t<T>;
return LuaImplQueryArg(instance, index, reinterpret_cast<SignedT*>(arg), static_cast<SignedT>(defValue), TypeTag<SignedT>());
}
template<typename T>
std::enable_if_t<!std::is_integral<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, const T& defValue, TypeTag<T> tag)
{
@ -148,26 +136,24 @@ namespace Nz
}
template<typename T>
std::enable_if_t<std::is_integral<T>::value && !std::is_unsigned<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
std::enable_if_t<std::is_integral<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
{
instance.PushInteger(val);
return 1;
}
template<typename T>
std::enable_if_t<std::is_unsigned<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
{
using SignedT = typename std::make_signed<T>::type;
return LuaImplReplyVal(instance, static_cast<SignedT>(val), TypeTag<SignedT>());
}
inline int LuaImplReplyVal(const LuaInstance& instance, std::string val, TypeTag<std::string>)
{
instance.PushString(val.c_str(), val.size());
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, ByteArray val, TypeTag<ByteArray>)
{
instance.PushString(reinterpret_cast<const char*>(val.GetConstBuffer()), val.GetSize());
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, String val, TypeTag<String>)
{
instance.PushString(std::move(val));
@ -420,6 +406,18 @@ namespace Nz
return object;
}
template<typename T>
inline T LuaInstance::CheckBoundInteger(int index) const
{
return CheckBounds<T>(index, CheckInteger(index));
}
template<typename T>
inline T LuaInstance::CheckBoundInteger(int index, T defValue) const
{
return CheckBounds<T>(index, CheckInteger(index, defValue));
}
template<typename T>
T LuaInstance::CheckField(const char* fieldName, int tableIndex) const
{
@ -550,4 +548,19 @@ namespace Nz
{
SetGlobal(name.GetConstBuffer(), std::forward<T>(arg));
}
template<typename T>
T LuaInstance::CheckBounds(int index, long long value) const
{
long long minBounds = std::numeric_limits<T>::min();
long long maxBounds = std::numeric_limits<T>::max();
if (value < minBounds || value > maxBounds)
{
Nz::StringStream stream;
stream << "Argument #" << index << " is outside value range [" << minBounds << ", " << maxBounds << "] (" << value << ')';
Error(stream);
}
return static_cast<T>(value);
}
}