Eluna changes

* Attempt fix VS 2010 pow error
* Tweak the doc parser a little to work with variable arugments ... and show
enum names and similar.
* Change push and check to work with more types like size and time (fix osx)
* Add errors to using not implemented operations on eluna objects
* Change some SQL comments to work with documentation better
* Add functions to create uint64 and int64 values (may need rename)
* Change doc generation documentation a little to make it clearer how proto is used
This commit is contained in:
Rochet2
2014-12-19 12:39:37 +02:00
parent 809a0ac2bc
commit 631e220b31
9 changed files with 200 additions and 121 deletions

View File

@@ -31,7 +31,7 @@ namespace LuaCorpse
*/
int GetGhostTime(Eluna* /*E*/, lua_State* L, Corpse* corpse)
{
Eluna::Push(L, uint32(corpse->GetGhostTime()));
Eluna::Push(L, corpse->GetGhostTime());
return 1;
}

View File

@@ -425,19 +425,21 @@ public:
return 1;
}
static int Add(lua_State* L) { return 0; }
static int Substract(lua_State* L) { return 0; }
static int Multiply(lua_State* L) { return 0; }
static int Divide(lua_State* L) { return 0; }
static int Mod(lua_State* L) { return 0; }
static int Pow(lua_State* L) { return 0; }
static int UnaryMinus(lua_State* L) { return 0; }
static int Concat(lua_State* L) { return 0; }
static int Length(lua_State* L) { return 0; }
static int Equal(lua_State* L) { return 0; }
static int Less(lua_State* L) { return 0; }
static int LessOrEqual(lua_State* L) { return 0; }
static int Call(lua_State* L) { return 0; }
static int ArithmeticError(lua_State* L) { return luaL_error(L, "attempt to perform arithmetic on a %s value", tname); }
static int CompareError(lua_State* L) { return luaL_error(L, "attempt to compare %s", tname); }
static int Add(lua_State* L) { return ArithmeticError(L); }
static int Substract(lua_State* L) { return ArithmeticError(L); }
static int Multiply(lua_State* L) { return ArithmeticError(L); }
static int Divide(lua_State* L) { return ArithmeticError(L); }
static int Mod(lua_State* L) { return ArithmeticError(L); }
static int Pow(lua_State* L) { return ArithmeticError(L); }
static int UnaryMinus(lua_State* L) { return ArithmeticError(L); }
static int Concat(lua_State* L) { return luaL_error(L, "attempt to concatenate a %s value", tname); }
static int Length(lua_State* L) { return luaL_error(L, "attempt to get length of a %s value", tname); }
static int Equal(lua_State* L) { Eluna::Push(L, Eluna::CHECKOBJ<T>(L, 1) == Eluna::CHECKOBJ<T>(L, 2)); return 1; }
static int Less(lua_State* L) { return CompareError(L); }
static int LessOrEqual(lua_State* L) { return CompareError(L); }
static int Call(lua_State* L) { return luaL_error(L, "attempt to call a %s value", tname); }
};
//
//template<typename T> const char* ElunaTemplate<T>::tname;

View File

@@ -113,11 +113,7 @@ namespace LuaGlobalFunctions
*/
int GetGameTime(Eluna* /*E*/, lua_State* L)
{
time_t time = eWorld->GetGameTime();
if (time < 0)
Eluna::Push(L, int32(time));
else
Eluna::Push(L, uint32(time));
Eluna::Push(L, eWorld->GetGameTime());
return 1;
}
@@ -1182,10 +1178,10 @@ namespace LuaGlobalFunctions
}
/**
* Executes world database sql [Query] instantly and returns QueryResult object
* Executes an sql to your world database instantly and returns [ElunaQuery]
*
* @param string query : sql [Query] to run
* @return QueryResult result
* @param string sql : sql to run
* @return [ElunaQuery] result
*/
int WorldDBQuery(Eluna* /*E*/, lua_State* L)
{
@@ -1208,9 +1204,9 @@ namespace LuaGlobalFunctions
}
/**
* Executes a sql [Query] (not instantly) to your world database
* Executes an sql to your character database. The SQL is not ran instantly.
*
* @param string query : sql [Query] to execute
* @param string sql : sql [ElunaQuery] to execute
*/
int WorldDBExecute(Eluna* /*E*/, lua_State* L)
{
@@ -1220,10 +1216,10 @@ namespace LuaGlobalFunctions
}
/**
* Executes character database sql [Query] instantly and returns QueryResult object
* Executes an sql to your character database instantly and returns [ElunaQuery]
*
* @param string query : sql [Query] to run
* @return [Query] result
* @param string sql : sql to run
* @return [ElunaQuery] result
*/
int CharDBQuery(Eluna* /*E*/, lua_State* L)
{
@@ -1246,9 +1242,9 @@ namespace LuaGlobalFunctions
}
/**
* Executes a [Query] (not instantly) to your character database
* Executes an sql to your character database. The SQL is not ran instantly.
*
* @param string query : sql [Query] to execute
* @param string sql : sql to run
*/
int CharDBExecute(Eluna* /*E*/, lua_State* L)
{
@@ -1258,10 +1254,10 @@ namespace LuaGlobalFunctions
}
/**
* Executes auth database sql [Query] instantly and returns QueryResult object
* Executes an sql to your auth database instantly and returns [ElunaQuery]
*
* @param string query : sql [Query] to run
* @return [Query] result
* @param string sql : sql to run
* @return [ElunaQuery] result
*/
int AuthDBQuery(Eluna* /*E*/, lua_State* L)
{
@@ -1284,9 +1280,9 @@ namespace LuaGlobalFunctions
}
/**
* Executes a [Query] (not instantly ) to your auth database
* Executes an sql to your auth database. The SQL is not ran instantly.
*
* @param string query : sql [Query] to execute
* @param string sql : sql to run
*/
int AuthDBExecute(Eluna* /*E*/, lua_State* L)
{
@@ -2493,5 +2489,63 @@ namespace LuaGlobalFunctions
ELUNA_LOG_DEBUG("%s", GetStackAsString(L).c_str());
return 0;
}
/**
* Returns an object represeting long long.
* The value by default is 0, but can be initialized to a value by passing a number or long long as a string.
*
* @proto value = ()
* @proto value = (number)
* @proto value = (longlong)
* @proto value = (longlongstr)
* @param int32 number : regular lua number
* @param int64 longlong : a long long object
* @param string longlongstr : a long long as a string
* @return int64 value
*/
int CreateLongLong(Eluna* /*E*/, lua_State* L)
{
long long init = 0;
if (lua_isstring(L, 1))
{
std::string str = Eluna::CHECKVAL<std::string>(L, 1);
if (sscanf(str.c_str(), SI64FMTD, &init) != 1)
return luaL_argerror(L, 1, "long long (as string) could not be converted");
}
else if (!lua_isnoneornil(L, 1))
init = Eluna::CHECKVAL<long long>(L, 1);
Eluna::Push(L, init);
return 1;
}
/**
* Returns an object represeting unsigned long long.
* The value by default is 0, but can be initialized to a value by passing a number or unsigned long long as a string.
*
* @proto value = ()
* @proto value = (number)
* @proto value = (ulonglong)
* @proto value = (ulonglongstr)
* @param uint32 number : regular lua number
* @param uint64 ulonglong : an unsigned long long object
* @param string ulonglongstr : an unsigned long long as a string
* @return uint64 value
*/
int CreateULongLong(Eluna* /*E*/, lua_State* L)
{
unsigned long long init = 0;
if (lua_isstring(L, 1))
{
std::string str = Eluna::CHECKVAL<std::string>(L, 1);
if (sscanf(str.c_str(), UI64FMTD, &init) != 1)
return luaL_argerror(L, 1, "unsigned long long (as string) could not be converted");
}
else if (!lua_isnoneornil(L, 1))
init = Eluna::CHECKVAL<unsigned long long>(L, 1);
Eluna::Push(L, init);
return 1;
}
}
#endif

View File

@@ -450,30 +450,30 @@ void Eluna::Push(lua_State* L)
{
lua_pushnil(L);
}
void Eluna::Push(lua_State* L, const uint64 l)
void Eluna::Push(lua_State* L, const long long l)
{
ElunaTemplate<uint64>::Push(L, new uint64(l));
ElunaTemplate<long long>::Push(L, new long long(l));
}
void Eluna::Push(lua_State* L, const int64 l)
void Eluna::Push(lua_State* L, const unsigned long long l)
{
ElunaTemplate<int64>::Push(L, new int64(l));
ElunaTemplate<unsigned long long>::Push(L, new unsigned long long(l));
}
//void Eluna::Push(lua_State* L, const time_t l)
//{
// ElunaTemplate<uint64>::Push(L, new uint64(l));
//}
//void Eluna::Push(lua_State* L, const size_t l)
//{
// ElunaTemplate<int64>::Push(L, new int64(l));
//}
void Eluna::Push(lua_State* L, const uint32 u)
void Eluna::Push(lua_State* L, const long l)
{
lua_pushunsigned(L, u);
Push(L, static_cast<long long>(l));
}
void Eluna::Push(lua_State* L, const int32 i)
void Eluna::Push(lua_State* L, const unsigned long l)
{
Push(L, static_cast<unsigned long long>(l));
}
void Eluna::Push(lua_State* L, const int i)
{
lua_pushinteger(L, i);
}
void Eluna::Push(lua_State* L, const unsigned int u)
{
lua_pushunsigned(L, u);
}
void Eluna::Push(lua_State* L, const double d)
{
lua_pushnumber(L, d);
@@ -486,7 +486,7 @@ void Eluna::Push(lua_State* L, const bool b)
{
lua_pushboolean(L, b);
}
void Eluna::Push(lua_State* L, const std::string str)
void Eluna::Push(lua_State* L, const std::string& str)
{
lua_pushstring(L, str.c_str());
}
@@ -572,29 +572,29 @@ void Eluna::Push(lua_State* L, Object const* obj)
}
}
static int32 CheckIntegerRange(lua_State* L, int narg, int32 min, int32 max)
static int CheckIntegerRange(lua_State* L, int narg, int min, int max)
{
int64 value = static_cast<int64>(luaL_checknumber(L, narg));
double value = luaL_checknumber(L, narg);
char error_buffer[64];
if (value > max)
{
snprintf(error_buffer, 64, "value must be less than or equal to %d", max);
snprintf(error_buffer, 64, "value must be less than or equal to %i", max);
return luaL_argerror(L, narg, error_buffer);
}
if (value < min)
{
snprintf(error_buffer, 64, "value must be greater than or equal to %d", min);
snprintf(error_buffer, 64, "value must be greater than or equal to %i", min);
return luaL_argerror(L, narg, error_buffer);
}
return static_cast<int32>(value);
return static_cast<int>(value);
}
static uint32 CheckUnsignedRange(lua_State* L, int narg, uint32 max)
static unsigned int CheckUnsignedRange(lua_State* L, int narg, unsigned int max)
{
int64 value = static_cast<int64>(luaL_checknumber(L, narg));
double value = luaL_checknumber(L, narg);
char error_buffer[64];
if (value < 0)
@@ -606,7 +606,7 @@ static uint32 CheckUnsignedRange(lua_State* L, int narg, uint32 max)
return luaL_argerror(L, narg, error_buffer);
}
return static_cast<uint32>(value);
return static_cast<unsigned int>(value);
}
template<> bool Eluna::CHECKVAL<bool>(lua_State* L, int narg)
@@ -621,27 +621,27 @@ template<> double Eluna::CHECKVAL<double>(lua_State* L, int narg)
{
return luaL_checknumber(L, narg);
}
template<> int8 Eluna::CHECKVAL<int8>(lua_State* L, int narg)
template<> signed char Eluna::CHECKVAL<signed char>(lua_State* L, int narg)
{
return CheckIntegerRange(L, narg, SCHAR_MIN, SCHAR_MAX);
}
template<> uint8 Eluna::CHECKVAL<uint8>(lua_State* L, int narg)
template<> unsigned char Eluna::CHECKVAL<unsigned char>(lua_State* L, int narg)
{
return CheckUnsignedRange(L, narg, UCHAR_MAX);
}
template<> int16 Eluna::CHECKVAL<int16>(lua_State* L, int narg)
template<> short Eluna::CHECKVAL<short>(lua_State* L, int narg)
{
return CheckIntegerRange(L, narg, SHRT_MIN, SHRT_MAX);
}
template<> uint16 Eluna::CHECKVAL<uint16>(lua_State* L, int narg)
template<> unsigned short Eluna::CHECKVAL<unsigned short>(lua_State* L, int narg)
{
return CheckUnsignedRange(L, narg, USHRT_MAX);
}
template<> int32 Eluna::CHECKVAL<int32>(lua_State* L, int narg)
template<> int Eluna::CHECKVAL<int>(lua_State* L, int narg)
{
return CheckIntegerRange(L, narg, INT_MIN, INT_MAX);
}
template<> uint32 Eluna::CHECKVAL<uint32>(lua_State* L, int narg)
template<> unsigned int Eluna::CHECKVAL<unsigned int>(lua_State* L, int narg)
{
return CheckUnsignedRange(L, narg, UINT_MAX);
}
@@ -653,30 +653,26 @@ template<> std::string Eluna::CHECKVAL<std::string>(lua_State* L, int narg)
{
return luaL_checkstring(L, narg);
}
template<> int64 Eluna::CHECKVAL<int64>(lua_State* L, int narg)
template<> long long Eluna::CHECKVAL<long long>(lua_State* L, int narg)
{
if (lua_isnumber(L, narg))
return static_cast<int64>(CHECKVAL<double>(L, narg));
return *(Eluna::CHECKOBJ<int64>(L, narg, true));
return static_cast<long long>(CHECKVAL<double>(L, narg));
return *(Eluna::CHECKOBJ<long long>(L, narg, true));
}
template<> uint64 Eluna::CHECKVAL<uint64>(lua_State* L, int narg)
template<> unsigned long long Eluna::CHECKVAL<unsigned long long>(lua_State* L, int narg)
{
if (lua_isnumber(L, narg))
return static_cast<uint64>(CHECKVAL<uint32>(L, narg));
return *(Eluna::CHECKOBJ<uint64>(L, narg, true));
return static_cast<unsigned long long>(CHECKVAL<uint32>(L, narg));
return *(Eluna::CHECKOBJ<unsigned long long>(L, narg, true));
}
template<> long Eluna::CHECKVAL<long>(lua_State* L, int narg)
{
return static_cast<long>(CHECKVAL<long long>(L, narg));
}
template<> unsigned long Eluna::CHECKVAL<unsigned long>(lua_State* L, int narg)
{
return static_cast<unsigned long>(CHECKVAL<unsigned long long>(L, narg));
}
//template<> time_t Eluna::CHECKVAL<time_t>(lua_State* L, int narg)
//{
// if (lua_isnumber(L, narg))
// return static_cast<time_t>(CHECKVAL<double>(L, narg));
// return static_cast<time_t>(*(Eluna::CHECKOBJ<int64>(L, narg, true)));
//}
//template<> size_t Eluna::CHECKVAL<size_t>(lua_State* L, int narg)
//{
// if (lua_isnumber(L, narg))
// return static_cast<size_t>(CHECKVAL<uint32>(L, narg));
// return static_cast<size_t>(*(Eluna::CHECKOBJ<uint64>(L, narg, true)));
//}
template<> Object* Eluna::CHECKOBJ<Object>(lua_State* L, int narg, bool error)
{

View File

@@ -160,15 +160,17 @@ public:
// Pushes
static void Push(lua_State* L); // nil
static void Push(lua_State* L, const uint64);
static void Push(lua_State* L, const int64);
static void Push(lua_State* L, const uint32);
static void Push(lua_State* L, const int32);
static void Push(lua_State* L, const long long);
static void Push(lua_State* L, const unsigned long long);
static void Push(lua_State* L, const long);
static void Push(lua_State* L, const unsigned long);
static void Push(lua_State* L, const int);
static void Push(lua_State* L, const unsigned int);
static void Push(lua_State* L, const bool);
static void Push(lua_State* L, const float);
static void Push(lua_State* L, const double);
static void Push(lua_State* L, const std::string&);
static void Push(lua_State* L, const char*);
static void Push(lua_State* L, const std::string);
template<typename T> static void Push(lua_State* L, T const* ptr)
{
ElunaTemplate<T>::Push(L, ptr);

View File

@@ -127,6 +127,8 @@ ElunaGlobal::ElunaRegister GlobalMethods[] =
{ "AddWeather", &LuaGlobalFunctions::AddWeather },
{ "RemoveWeather", &LuaGlobalFunctions::RemoveWeather },
{ "SendFineWeatherToPlayer", &LuaGlobalFunctions::SendFineWeatherToPlayer },
{ "CreateInt64", &LuaGlobalFunctions::CreateLongLong },
{ "CreateUint64", &LuaGlobalFunctions::CreateULongLong },
{ NULL, NULL },
};
@@ -1266,38 +1268,46 @@ template<> int ElunaTemplate<Vehicle>::CollectGarbage(lua_State* L)
#endif
// Template by Mud from http://stackoverflow.com/questions/4484437/lua-integer-type/4485511#4485511
template<> int ElunaTemplate<uint64>::Add(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<uint64>(L, 1) + Eluna::CHECKVAL<uint64>(L, 2)); return 1; }
template<> int ElunaTemplate<uint64>::Substract(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<uint64>(L, 1) - Eluna::CHECKVAL<uint64>(L, 2)); return 1; }
template<> int ElunaTemplate<uint64>::Multiply(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<uint64>(L, 1) * Eluna::CHECKVAL<uint64>(L, 2)); return 1; }
template<> int ElunaTemplate<uint64>::Divide(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<uint64>(L, 1) / Eluna::CHECKVAL<uint64>(L, 2)); return 1; }
template<> int ElunaTemplate<uint64>::Mod(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<uint64>(L, 1) % Eluna::CHECKVAL<uint64>(L, 2)); return 1; }
template<> int ElunaTemplate<uint64>::Pow(lua_State* L) { Eluna::Push(L, pow(Eluna::CHECKVAL<uint64>(L, 1), Eluna::CHECKVAL<uint64>(L, 2))); return 1; }
// template<> int ElunaTemplate<uint64>::UnaryMinus(lua_State* L) { Eluna::Push(L, -Eluna::CHECKVAL<uint64>(L, 1)); return 1; }
template<> int ElunaTemplate<uint64>::Equal(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<uint64>(L, 1) == Eluna::CHECKVAL<uint64>(L, 2)); return 1; }
template<> int ElunaTemplate<uint64>::Less(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<uint64>(L, 1) < Eluna::CHECKVAL<uint64>(L, 2)); return 1; }
template<> int ElunaTemplate<uint64>::LessOrEqual(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<uint64>(L, 1) <= Eluna::CHECKVAL<uint64>(L, 2)); return 1; }
template<> int ElunaTemplate<uint64>::ToString(lua_State* L)
template<> int ElunaTemplate<unsigned long long>::Add(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<unsigned long long>(L, 1) + Eluna::CHECKVAL<unsigned long long>(L, 2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Substract(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<unsigned long long>(L, 1) - Eluna::CHECKVAL<unsigned long long>(L, 2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Multiply(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<unsigned long long>(L, 1) * Eluna::CHECKVAL<unsigned long long>(L, 2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Divide(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<unsigned long long>(L, 1) / Eluna::CHECKVAL<unsigned long long>(L, 2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Mod(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<unsigned long long>(L, 1) % Eluna::CHECKVAL<unsigned long long>(L, 2)); return 1; }
// template<> int ElunaTemplate<unsigned long long>::UnaryMinus(lua_State* L) { Eluna::Push(L, -Eluna::CHECKVAL<unsigned long long>(L, 1)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Equal(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<unsigned long long>(L, 1) == Eluna::CHECKVAL<unsigned long long>(L, 2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Less(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<unsigned long long>(L, 1) < Eluna::CHECKVAL<unsigned long long>(L, 2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::LessOrEqual(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<unsigned long long>(L, 1) <= Eluna::CHECKVAL<unsigned long long>(L, 2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Pow(lua_State* L)
{
uint64 l = Eluna::CHECKVAL<uint64>(L, 1);
Eluna::Push(L, static_cast<unsigned long long>(std::powl(static_cast<long double>(Eluna::CHECKVAL<unsigned long long>(L, 1)), static_cast<long double>(Eluna::CHECKVAL<unsigned long long>(L, 2)))));
return 1;
}
template<> int ElunaTemplate<unsigned long long>::ToString(lua_State* L)
{
unsigned long long l = Eluna::CHECKVAL<unsigned long long>(L, 1);
std::ostringstream ss;
ss << l;
Eluna::Push(L, ss.str());
return 1;
}
template<> int ElunaTemplate<int64>::Add(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<int64>(L, 1) + Eluna::CHECKVAL<int64>(L, 2)); return 1; }
template<> int ElunaTemplate<int64>::Substract(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<int64>(L, 1) - Eluna::CHECKVAL<int64>(L, 2)); return 1; }
template<> int ElunaTemplate<int64>::Multiply(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<int64>(L, 1) * Eluna::CHECKVAL<int64>(L, 2)); return 1; }
template<> int ElunaTemplate<int64>::Divide(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<int64>(L, 1) / Eluna::CHECKVAL<int64>(L, 2)); return 1; }
template<> int ElunaTemplate<int64>::Mod(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<int64>(L, 1) % Eluna::CHECKVAL<int64>(L, 2)); return 1; }
template<> int ElunaTemplate<int64>::Pow(lua_State* L) { Eluna::Push(L, pow(Eluna::CHECKVAL<int64>(L, 1), Eluna::CHECKVAL<int64>(L, 2))); return 1; }
template<> int ElunaTemplate<int64>::UnaryMinus(lua_State* L) { Eluna::Push(L, -Eluna::CHECKVAL<int64>(L, 1)); return 1; }
template<> int ElunaTemplate<int64>::Equal(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<int64>(L, 1) == Eluna::CHECKVAL<int64>(L, 2)); return 1; }
template<> int ElunaTemplate<int64>::Less(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<int64>(L, 1) < Eluna::CHECKVAL<int64>(L, 2)); return 1; }
template<> int ElunaTemplate<int64>::LessOrEqual(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<int64>(L, 1) <= Eluna::CHECKVAL<int64>(L, 2)); return 1; }
template<> int ElunaTemplate<int64>::ToString(lua_State* L)
template<> int ElunaTemplate<long long>::Add(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<long long>(L, 1) + Eluna::CHECKVAL<long long>(L, 2)); return 1; }
template<> int ElunaTemplate<long long>::Substract(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<long long>(L, 1) - Eluna::CHECKVAL<long long>(L, 2)); return 1; }
template<> int ElunaTemplate<long long>::Multiply(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<long long>(L, 1) * Eluna::CHECKVAL<long long>(L, 2)); return 1; }
template<> int ElunaTemplate<long long>::Divide(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<long long>(L, 1) / Eluna::CHECKVAL<long long>(L, 2)); return 1; }
template<> int ElunaTemplate<long long>::Mod(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<long long>(L, 1) % Eluna::CHECKVAL<long long>(L, 2)); return 1; }
template<> int ElunaTemplate<long long>::UnaryMinus(lua_State* L) { Eluna::Push(L, -Eluna::CHECKVAL<long long>(L, 1)); return 1; }
template<> int ElunaTemplate<long long>::Equal(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<long long>(L, 1) == Eluna::CHECKVAL<long long>(L, 2)); return 1; }
template<> int ElunaTemplate<long long>::Less(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<long long>(L, 1) < Eluna::CHECKVAL<long long>(L, 2)); return 1; }
template<> int ElunaTemplate<long long>::LessOrEqual(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<long long>(L, 1) <= Eluna::CHECKVAL<long long>(L, 2)); return 1; }
template<> int ElunaTemplate<long long>::Pow(lua_State* L)
{
int64 l = Eluna::CHECKVAL<int64>(L, 1);
Eluna::Push(L, static_cast<long long>(std::powl(static_cast<long double>(Eluna::CHECKVAL<long long>(L, 1)), static_cast<long double>(Eluna::CHECKVAL<long long>(L, 2)))));
return 1;
}
template<> int ElunaTemplate<long long>::ToString(lua_State* L)
{
long long l = Eluna::CHECKVAL<long long>(L, 1);
std::ostringstream ss;
ss << l;
Eluna::Push(L, ss.str());
@@ -1386,7 +1396,7 @@ void RegisterFunctions(Eluna* E)
ElunaTemplate<ElunaQuery>::Register(E, "ElunaQuery", true);
ElunaTemplate<ElunaQuery>::SetMethods(E, QueryMethods);
ElunaTemplate<uint64>::Register(E, "uint64", true);
ElunaTemplate<long long>::Register(E, "long long", true);
ElunaTemplate<int64>::Register(E, "int64", true);
ElunaTemplate<unsigned long long>::Register(E, "unsigned long long", true);
}

View File

@@ -43,7 +43,10 @@ This is a template for a function that takes in different parameters. When defin
*
* @proto returnValue = (object)
* @proto returnValue = (x, y, z)
* @param Type paramName = defaultValue : parameter description
* @param [WorldObject] object = defaultValue : parameter description
* @param float x = defaultValue : parameter description
* @param float y = defaultValue : parameter description
* @param float z = defaultValue : parameter description
* @return Type returnName : return value description
*/
```

View File

@@ -118,6 +118,7 @@ if __name__ == '__main__':
'string': 'http://www.lua.org/pil/2.4.html',
'table': 'http://www.lua.org/pil/2.5.html',
'function': 'http://www.lua.org/pil/2.6.html',
'...': 'http://www.lua.org/pil/5.2.html',
}
def data_type_parser(content):
@@ -132,6 +133,8 @@ if __name__ == '__main__':
url = '{}{}/index.html'.format(('../' * level), class_name)
return '<strong><a class="mod" href="{}">{}</a></strong>'.format(url, class_name)
return content[1:-1]
return link_parser, data_type_parser
# Create the render function with the template path and parser maker.

View File

@@ -18,6 +18,8 @@ class ParameterDoc(object):
'uint16': ('0', '65,535'),
'int32': ('-2,147,483,647', '2,147,483,647'),
'uint32': ('0', '4,294,967,295'),
'int64': ('-9,223,372,036,854,775,808', '9,223,372,036,854,775,807'),
'uint64': ('0', '18,446,744,073,709,551,615'),
}
@params(self=object, name=unicode, data_type=str, description=unicode, default_value=Nullable(unicode))
@@ -47,8 +49,8 @@ class ParameterDoc(object):
elif self.data_type == 'bool':
self.data_type = 'boolean'
elif self.data_type == 'uint64' or self.data_type == 'int64':
self.data_type = 'string'
elif self.data_type == 'int64' or self.data_type == 'uint64':
self.data_type = '[' + self.data_type + ']'
class MethodDoc(object):
@@ -112,7 +114,7 @@ class ClassParser(object):
# An extra optional space (\s?) was thrown in to make it different from `class_body_regex`.
param_regex = re.compile(r"""\s*\*\s@param\s # The @param tag starts with opt. whitespace followed by "* @param ".
([\[\]\w]+)\s(\w+) # The data type, a space, and the name of the param.
([^\s]+)\s(\w+) # The data type, a space, and the name of the param.
(?:\s=\s(\w+))? # The default value: a = surrounded by spaces, followed by text.
(?:\s:\s(.+))? # The description: a colon surrounded by spaces, followed by text.
""", re.X)
@@ -183,11 +185,18 @@ class ClassParser(object):
if parameters != '':
parameters = ' ' + parameters + ' '
if self.returned:
return_values = ', '.join([param.name for param in self.returned])
prototype = '{0} = {1}:{2}({3})'.format(return_values, self.class_name, self.method_name, parameters)
if self.class_name == 'Global':
if self.returned:
return_values = ', '.join([param.name for param in self.returned])
prototype = '{0} = {1}({2})'.format(return_values, self.method_name, parameters)
else:
prototype = '{0}({1})'.format(self.method_name, parameters)
else:
prototype = '{0}:{1}({2})'.format(self.class_name, self.method_name, parameters)
if self.returned:
return_values = ', '.join([param.name for param in self.returned])
prototype = '{0} = {1}:{2}({3})'.format(return_values, self.class_name, self.method_name, parameters)
else:
prototype = '{0}:{1}({2})'.format(self.class_name, self.method_name, parameters)
self.prototypes.append(prototype)
else: