Merge pull request #53 from GigAnon/master

Added Lua Bindings

Former-commit-id: 18587c489da05c97e7b9670eaf526eda4210f983
This commit is contained in:
Lynix 2016-01-22 10:01:28 +01:00
commit a32a1d428f
21 changed files with 1235 additions and 16 deletions

2
.gitignore vendored
View File

@ -1,5 +1,6 @@
# Nazara build # Nazara build
examples/bin/*.exe examples/bin/*.exe
tests/*.exe
lib/* lib/*
# Feature page # Feature page
@ -28,6 +29,7 @@ build/**/*.sln
build/**/*.vcxprojResolveAssemblyReference.cache build/**/*.vcxprojResolveAssemblyReference.cache
build/**/*.nativecodeanalysis.all.xml build/**/*.nativecodeanalysis.all.xml
build/**/*.nativecodeanalysis.xml build/**/*.nativecodeanalysis.xml
build/**/*.VC.opendb
lib/*.exp lib/*.exp
# Compiled Object files # Compiled Object files

View File

@ -25,6 +25,9 @@ namespace Ndk
static void Register_Audio(Nz::LuaInstance& instance); static void Register_Audio(Nz::LuaInstance& instance);
static void Register_Core(Nz::LuaInstance& instance); static void Register_Core(Nz::LuaInstance& instance);
static void Register_Math(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_Renderer(Nz::LuaInstance& instance);
}; };
} }

View File

@ -48,6 +48,16 @@ namespace Nz
return ret; return ret;
} }
inline unsigned int LuaImplQueryArg(const LuaInstance& lua, int index, Vector3ui* vec, TypeTag<Vector3ui>)
{
Vector3d vecDouble;
unsigned int ret = LuaImplQueryArg(lua, index, &vecDouble, TypeTag<Vector3d>());
vec->Set(vecDouble);
return ret;
}
inline int LuaImplReplyVal(const LuaInstance& instance, const SoundBuffer* val, TypeTag<const SoundBuffer*>) inline int LuaImplReplyVal(const LuaInstance& instance, const SoundBuffer* val, TypeTag<const SoundBuffer*>)
{ {
instance.PushInstance<SoundBufferConstRef>("SoundBuffer", val); instance.PushInstance<SoundBufferConstRef>("SoundBuffer", val);
@ -65,4 +75,10 @@ namespace Nz
instance.PushInstance<Vector3d>("Vector3", val); instance.PushInstance<Vector3d>("Vector3", val);
return 1; return 1;
} }
inline int LuaImplReplyVal(const LuaInstance& instance, Vector3ui val, TypeTag<Vector3ui>)
{
instance.PushInstance<Vector3d>("Vector3", val);
return 1;
}
} }

View File

@ -108,7 +108,7 @@ namespace Ndk
soundClass.SetMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams()); soundClass.SetMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams());
soundClass.SetMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset); soundClass.SetMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset);
// Nz::Clock::__tostring (Manual) // Nz::Sound::__tostring (Manual)
soundClass.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& sound) -> int { soundClass.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& sound) -> int {
Nz::StringStream stream("Sound("); Nz::StringStream stream("Sound(");
if (const Nz::SoundBuffer* buffer = sound.GetBuffer()) if (const Nz::SoundBuffer* buffer = sound.GetBuffer())

View File

@ -4,10 +4,75 @@
#include <Nazara/Core.hpp> #include <Nazara/Core.hpp>
#include <Nazara/Lua/LuaClass.hpp> #include <Nazara/Lua/LuaClass.hpp>
#include <Nazara/Core/Hash/MD5.hpp>
namespace Ndk namespace Ndk
{ {
void LuaAPI::Register_Core(Nz::LuaInstance& instance) 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::Clock **********************************/
Nz::LuaClass<Nz::Clock> clockClass("Clock"); Nz::LuaClass<Nz::Clock> clockClass("Clock");

View File

@ -0,0 +1,15 @@
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/LuaAPI.hpp>
#include <Nazara/Graphics.hpp>
#include <Nazara/Lua/LuaClass.hpp>
namespace Ndk
{
void LuaAPI::Register_Graphics(Nz::LuaInstance& instance)
{
}
}

View File

@ -8,10 +8,118 @@ namespace Ndk
{ {
void LuaAPI::Register_Math(Nz::LuaInstance& instance) void LuaAPI::Register_Math(Nz::LuaInstance& instance)
{ {
/*********************************** Nz::Vector3 **********************************/ /*********************************** Nz::Vector2 **********************************/
Nz::LuaClass<Nz::Vector3d> vectorClass("Vector3"); Nz::LuaClass<Nz::Vector2d> vector2dClass("Vector2");
vectorClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Vector3d* { vector2dClass.SetConstructor(
[](Nz::LuaInstance& lua) -> Nz::Vector2d*
{
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:
{
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;
}
}
lua.Error("No matching overload for Vector2 constructor");
return nullptr;
});
vector2dClass.SetMethod("__tostring", &Nz::Vector2d::ToString);
vector2dClass.SetGetter(
[](Nz::LuaInstance& lua, Nz::Vector2d& instance)
{
switch (lua.GetType(1))
{
case Nz::LuaType_Number:
lua.Push(instance[lua.CheckInteger(1)]);
return true;
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;
}
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;
}
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;
}
break;
}
}
return false;
});
vector2dClass.Register(instance);
/*********************************** Nz::Vector3 **********************************/
Nz::LuaClass<Nz::Vector3d> vector3dClass("Vector3");
vector3dClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Vector3d* {
unsigned int argCount = std::min(lua.GetStackTop(), 3U); unsigned int argCount = std::min(lua.GetStackTop(), 3U);
switch (argCount) switch (argCount)
{ {
@ -46,9 +154,9 @@ namespace Ndk
return nullptr; return nullptr;
}); });
vectorClass.SetMethod("__tostring", &Nz::Vector3d::ToString); vector3dClass.SetMethod("__tostring", &Nz::Vector3d::ToString);
vectorClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance) vector3dClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance)
{ {
switch (lua.GetType(1)) switch (lua.GetType(1))
{ {
@ -85,7 +193,7 @@ namespace Ndk
return false; return false;
}); });
vectorClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance) vector3dClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance)
{ {
switch (lua.GetType(1)) switch (lua.GetType(1))
{ {
@ -130,6 +238,6 @@ namespace Ndk
return false; return false;
}); });
vectorClass.Register(instance); vector3dClass.Register(instance);
} }
} }

View File

@ -0,0 +1,148 @@
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/LuaAPI.hpp>
#include <Nazara/Renderer.hpp>
#include <Nazara/Lua/LuaClass.hpp>
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

@ -0,0 +1,14 @@
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/LuaAPI.hpp>
#include <Nazara/Utility.hpp>
#include <Nazara/Lua/LuaClass.hpp>
namespace Ndk
{
void LuaAPI::Register_Utility(Nz::LuaInstance& instance)
{
}
}

View File

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

View File

@ -1 +1 @@
premake4 --with-extlibs --with-examples codelite premake5 --with-extlibs --with-examples codelite

View File

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

View File

@ -1 +0,0 @@
premake4 --with-extlibs --with-examples vs2013

View File

@ -1 +0,0 @@
premake4 --united --with-extlibs --with-examples vs2013

View File

@ -0,0 +1 @@
premake5 --with-extlibs --with-examples vs2015

View File

@ -0,0 +1 @@
premake5 --united --with-extlibs --with-examples vs2015

View File

@ -1,2 +1,2 @@
premake4 encoderesources premake5 encoderesources
pause pause

View File

@ -1,2 +1,2 @@
premake4 generateheaders premake5 generateheaders
pause pause

View File

@ -1,2 +1,2 @@
premake4 parseunicode premake5 parseunicode
pause pause

839
build/scripts/common5.lua Normal file
View File

@ -0,0 +1,839 @@
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,6 +15,7 @@
#include <Nazara/Lua/Enums.hpp> #include <Nazara/Lua/Enums.hpp>
#include <cstddef> #include <cstddef>
#include <functional> #include <functional>
#include <limits>
struct lua_Debug; struct lua_Debug;
struct lua_State; struct lua_State;
@ -189,6 +190,14 @@ namespace Nz
lua_State* m_state; lua_State* m_state;
unsigned int m_level; 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> #include <Nazara/Lua/LuaInstance.inl>