Fix calling Eluna functions from coroutines.

Fixes #126.
This commit is contained in:
Patman64
2014-12-15 00:33:46 -05:00
parent 3f08b37fd0
commit 967a8045eb
21 changed files with 2548 additions and 2548 deletions

View File

@@ -14,152 +14,152 @@
#endif
namespace LuaQuery
{
void CheckFields(Eluna* E, ElunaQuery* result)
void CheckFields(Eluna* /*E*/, lua_State* L, ElunaQuery* result)
{
if (Eluna::CHECKVAL<uint32>(E->L, 2) >= RESULT->GetFieldCount())
luaL_argerror(E->L, 2, "invalid field index");
if (Eluna::CHECKVAL<uint32>(L, 2) >= RESULT->GetFieldCount())
luaL_argerror(L, 2, "invalid field index");
}
/* BOOLEAN */
int IsNull(Eluna* E, ElunaQuery* result)
int IsNull(Eluna* E, lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(E, result);
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
CheckFields(E, L, result);
#ifndef TRINITY
Eluna::Push(E->L, RESULT->Fetch()[col].IsNULL());
Eluna::Push(L, RESULT->Fetch()[col].IsNULL());
#else
Eluna::Push(E->L, RESULT->Fetch()[col].IsNull());
Eluna::Push(L, RESULT->Fetch()[col].IsNull());
#endif
return 1;
}
/* GETTERS */
int GetColumnCount(Eluna* E, ElunaQuery* result)
int GetColumnCount(Eluna* /*E*/, lua_State* L, ElunaQuery* result)
{
Eluna::Push(E->L, RESULT->GetFieldCount());
Eluna::Push(L, RESULT->GetFieldCount());
return 1;
}
int GetRowCount(Eluna* E, ElunaQuery* result)
int GetRowCount(Eluna* /*E*/, lua_State* L, ElunaQuery* result)
{
if (RESULT->GetRowCount() > (uint32)-1)
Eluna::Push(E->L, (uint32)-1);
Eluna::Push(L, (uint32)-1);
else
Eluna::Push(E->L, RESULT->GetRowCount());
Eluna::Push(L, RESULT->GetRowCount());
return 1;
}
int GetBool(Eluna* E, ElunaQuery* result)
int GetBool(Eluna* E, lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(E, result);
Eluna::Push(E->L, RESULT->Fetch()[col].GetBool());
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
CheckFields(E, L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetBool());
return 1;
}
int GetUInt8(Eluna* E, ElunaQuery* result)
int GetUInt8(Eluna* E, lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(E, result);
Eluna::Push(E->L, RESULT->Fetch()[col].GetUInt8());
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
CheckFields(E, L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetUInt8());
return 1;
}
int GetUInt16(Eluna* E, ElunaQuery* result)
int GetUInt16(Eluna* E, lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(E, result);
Eluna::Push(E->L, RESULT->Fetch()[col].GetUInt16());
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
CheckFields(E, L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetUInt16());
return 1;
}
int GetUInt32(Eluna* E, ElunaQuery* result)
int GetUInt32(Eluna* E, lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(E, result);
Eluna::Push(E->L, RESULT->Fetch()[col].GetUInt32());
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
CheckFields(E, L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetUInt32());
return 1;
}
int GetUInt64(Eluna* E, ElunaQuery* result)
int GetUInt64(Eluna* E, lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(E, result);
Eluna::Push(E->L, RESULT->Fetch()[col].GetUInt64());
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
CheckFields(E, L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetUInt64());
return 1;
}
int GetInt8(Eluna* E, ElunaQuery* result)
int GetInt8(Eluna* E, lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(E, result);
Eluna::Push(E->L, RESULT->Fetch()[col].GetInt8());
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
CheckFields(E, L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetInt8());
return 1;
}
int GetInt16(Eluna* E, ElunaQuery* result)
int GetInt16(Eluna* E, lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(E, result);
Eluna::Push(E->L, RESULT->Fetch()[col].GetInt16());
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
CheckFields(E, L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetInt16());
return 1;
}
int GetInt32(Eluna* E, ElunaQuery* result)
int GetInt32(Eluna* E, lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(E, result);
Eluna::Push(E->L, RESULT->Fetch()[col].GetInt32());
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
CheckFields(E, L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetInt32());
return 1;
}
int GetInt64(Eluna* E, ElunaQuery* result)
int GetInt64(Eluna* E, lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(E, result);
Eluna::Push(E->L, RESULT->Fetch()[col].GetInt64());
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
CheckFields(E, L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetInt64());
return 1;
}
int GetFloat(Eluna* E, ElunaQuery* result)
int GetFloat(Eluna* E, lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(E, result);
Eluna::Push(E->L, RESULT->Fetch()[col].GetFloat());
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
CheckFields(E, L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetFloat());
return 1;
}
int GetDouble(Eluna* E, ElunaQuery* result)
int GetDouble(Eluna* E, lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(E, result);
Eluna::Push(E->L, RESULT->Fetch()[col].GetDouble());
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
CheckFields(E, L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetDouble());
return 1;
}
int GetString(Eluna* E, ElunaQuery* result)
int GetString(Eluna* E, lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(E, result);
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
CheckFields(E, L, result);
#ifndef TRINITY
Eluna::Push(E->L, RESULT->Fetch()[col].GetCppString());
Eluna::Push(L, RESULT->Fetch()[col].GetCppString());
#else
Eluna::Push(E->L, RESULT->Fetch()[col].GetString());
Eluna::Push(L, RESULT->Fetch()[col].GetString());
#endif
return 1;
}
int GetCString(Eluna* E, ElunaQuery* result)
int GetCString(Eluna* E, lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(E, result);
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
CheckFields(E, L, result);
#ifndef TRINITY
Eluna::Push(E->L, RESULT->Fetch()[col].GetString());
Eluna::Push(L, RESULT->Fetch()[col].GetString());
#else
Eluna::Push(E->L, RESULT->Fetch()[col].GetCString());
Eluna::Push(L, RESULT->Fetch()[col].GetCString());
#endif
return 1;
}
@@ -172,9 +172,9 @@ namespace LuaQuery
*
* @return bool hadNextRow
*/
int NextRow(Eluna* E, ElunaQuery* result)
int NextRow(Eluna* /*E*/, lua_State* L, ElunaQuery* result)
{
Eluna::Push(E->L, RESULT->NextRow());
Eluna::Push(L, RESULT->NextRow());
return 1;
}
@@ -186,10 +186,10 @@ namespace LuaQuery
*
* @return table rowData : table filled with row columns and data where `T[column] = data`
*/
int GetRow(Eluna* E, ElunaQuery* result)
int GetRow(Eluna* /*E*/, lua_State* L, ElunaQuery* result)
{
lua_newtable(E->L);
int tbl = lua_gettop(E->L);
lua_newtable(L);
int tbl = lua_gettop(L);
uint32 col = RESULT->GetFieldCount();
Field* row = RESULT->Fetch();
@@ -201,17 +201,17 @@ namespace LuaQuery
for (uint32 i = 0; i < col; ++i)
{
#ifdef TRINITY
Eluna::Push(E->L, RESULT->GetFieldName(i));
Eluna::Push(L, RESULT->GetFieldName(i));
const char* str = row[i].GetCString();
if (row[i].IsNull() || !str)
Eluna::Push(E->L);
Eluna::Push(L);
#else
Eluna::Push(E->L, names[i]);
Eluna::Push(L, names[i]);
const char* str = row[i].GetString();
if (row[i].IsNULL() || !str)
Eluna::Push(E->L);
Eluna::Push(L);
#endif
else
{
@@ -224,18 +224,18 @@ namespace LuaQuery
case MYSQL_TYPE_LONG:
case MYSQL_TYPE_FLOAT:
case MYSQL_TYPE_DOUBLE:
Eluna::Push(E->L, strtod(str, NULL));
Eluna::Push(L, strtod(str, NULL));
break;
default:
Eluna::Push(E->L, str);
Eluna::Push(L, str);
break;
}
}
lua_settable(E->L, tbl);
lua_settable(L, tbl);
}
lua_settop(E->L, tbl);
lua_settop(L, tbl);
return 1;
}
};