I have been trying to make a function in C++ for a gameserver DLL which aligns given text to center before returning the new string to Lua for processing. I have spent quite a lot of time looking at examples on various sites but have only been able to find 'cout', which prints it in the console application, which I do not want it to do.
I'm new to C++, and I'm really confused on how to approach this. If someone would be able to provide an example and explain how it works, I'll be able to learn how to do this for the future.
Basically, it does this:
- Forward our string from Lua to C++.
- C++ centers the string that we just forwarded.
- Return the completed string back to Lua.
Here's a sample of what I've been trying to do:
int CScriptBind_GameRules::CentreTextForConsole(IFunctionHandler *pH, const char *input)
{
if (input)
{
int l=strlen(input);
int pos=(int)((113-l)/2);
for(int i=0;i<pos;i++)
std::cout<<" ";
std::cout<<input;
return pH->EndFunction(input);
}
else
{
CryLog("[System] Error in CScriptBind_GameRules::CentreTextForConsole: Failed to align");
return pH->EndFunction();
}
return pH->EndFunction();
}
Which builds but it prints the text to the console, not forwarding back the completed string.