1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-09 01:07:16 +01:00
SqMod/modules/irc/Common.cpp
Sandu Liviu Catalin 40ab83743c Update the IRC module to work with the modified API.
Document code properly and also various code fixes.
2016-06-03 21:27:53 +03:00

122 lines
4.0 KiB
C++

// ------------------------------------------------------------------------------------------------
#include "Common.hpp"
// ------------------------------------------------------------------------------------------------
#include <cstdlib>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQInteger GetNick(HSQUIRRELVM vm)
{
// Attempt to retrieve the value from the stack as a string
StackStrF val(vm, 2);
// Have we failed to retrieve the string?
if (SQ_FAILED(val.mRes))
{
return val.mRes; // Propagate the error!
}
// Attempt to retrieve the nickname
irc_target_get_nick(val.mPtr, GetTempBuff(), GetTempBuffSize());
// Push the resulted value on the stack
sq_pushstring(vm, GetTempBuff(), -1);
// Specify that this function returned a value
return 1;
}
// ------------------------------------------------------------------------------------------------
SQInteger GetHost(HSQUIRRELVM vm)
{
// Attempt to retrieve the value from the stack as a string
StackStrF val(vm, 2);
// Have we failed to retrieve the string?
if (SQ_FAILED(val.mRes))
{
return val.mRes; // Propagate the error!
}
// Attempt to retrieve the host
irc_target_get_host(val.mPtr, GetTempBuff(), GetTempBuffSize());
// Push the resulted value on the stack
sq_pushstring(vm, GetTempBuff(), -1);
// Specify that this function returned a value
return 1;
}
// ------------------------------------------------------------------------------------------------
SQInteger StripColorFromMIRC(HSQUIRRELVM vm)
{
// Attempt to retrieve the value from the stack as a string
StackStrF val(vm, 2);
// Have we failed to retrieve the string?
if (SQ_FAILED(val.mRes))
{
return val.mRes; // Propagate the error!
}
// Attempt to strip the colors
CStr str = irc_color_strip_from_mirc(val.mPtr);
// Could the IRC library allocate memory?
if (!str)
{
return sq_throwerror(vm, _SC("Unable to allocate memory"));
}
// Push the resulted value on the stack
sq_pushstring(vm, str, -1);
// Free the memory allocated by the IRC library
std::free(str);
// Specify that this function returned a value
return 1;
}
// ------------------------------------------------------------------------------------------------
SQInteger ConvertColorFromMIRC(HSQUIRRELVM vm)
{
// Attempt to retrieve the value from the stack as a string
StackStrF val(vm, 2);
// Have we failed to retrieve the string?
if (SQ_FAILED(val.mRes))
{
return val.mRes; // Propagate the error!
}
// Attempt to convert the colors
CStr str = irc_color_convert_from_mirc(val.mPtr);
// Could the IRC library allocate memory?
if (!str)
{
return sq_throwerror(vm, _SC("Unable to allocate memory"));
}
// Push the resulted value on the stack
sq_pushstring(vm, str, -1);
// Free the memory allocated by the IRC library
std::free(str);
// Specify that this function returned a value
return 1;
}
// ------------------------------------------------------------------------------------------------
SQInteger ConvertColorToMIRC(HSQUIRRELVM vm)
{
// Attempt to retrieve the value from the stack as a string
StackStrF val(vm, 2);
// Have we failed to retrieve the string?
if (SQ_FAILED(val.mRes))
{
return val.mRes; // Propagate the error!
}
// Attempt to convert the colors
CStr str = irc_color_convert_to_mirc(val.mPtr);
// Could the IRC library allocate memory?
if (!str)
{
return sq_throwerror(vm, _SC("Unable to allocate memory"));
}
// Push the resulted value on the stack
sq_pushstring(vm, str, -1);
// Free the memory allocated by the IRC library
std::free(str);
// Specify that this function returned a value
return 1;
}
} // Namespace:: SqMod