-
-
Notifications
You must be signed in to change notification settings - Fork 437
Using `argStream.ReadEnumString`
function ReadEnumString
is used for white-listing string value.
If you want add example that umpteenth argument is equal "one", "two" or "three", you have to follow steps below:
- declare your enum
enum eNumbers
{
ONE,
TWO,
THREE,
}
in header file related to application, example mtasa-blue\Client\mods\deathmatch\logic\lua\CLuaFunctionParseHelpers.h
-
In file
mtasa-blue\Client\mods\deathmatch\logic\lua\CLuaFunctionParseHelpers.h
below othersDECLARE_ENUM
you add your declaration of enum:DECLARE_ENUM(eNumbers)
-
In same file, below others
GetClassTypeName
you have to add following lines defined what name is displayed if error occurs.
inline SString GetClassTypeName(eNumbers*)
{
return "number";
}
- Now move to
mtasa-blue\Client\mods\deathmatch\logic\lua\CLuaFunctionParseHelpers.cpp
file and add what every enum field mean. Goto below othersIMPLEMENT_ENUM_BEGIN
,ADD_ENUM
andIMPLEMENT_ENUM_END
declaration, and add your enum:
IMPLEMENT_ENUM_BEGIN(eNumbers)
// ^ enum name.
ADD_ENUM(ONE, "one")
ADD_ENUM(TWO, "two")
ADD_ENUM(THREE, "three")
// THREE is field in enum, second argument is friendly string which user put at specified argument.
IMPLEMENT_ENUM_END("number")
// ^ name displayed for user if error occur. should be same as above.
Now, you can use your enum in function, example:
CScriptArgReader argStream(luaVM);
eNumbers eNumber;
argStream.ReadEnumString(eNumber);
if (!argStream.HasErrors())
{
lua_pushnumber(luaVM, eNumber)
return 1;
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
lua_pushboolean(luaVM, false);
return 1;
Example this function is called convertStringToNumber
where first argument is our enum,
now in lua
convertStringToNumber( "one" ) -- return: 1
convertStringToNumber( "two" ) -- return: 2
convertStringToNumber("three") -- return: 3
convertStringToNumber( "four" ) -- return false and throw error with information that first argument should be `number`.
Authors: CrosRoad95, Shaviq
Project Management
Git cheat sheet
Release Checklist
Code Review
Documentation
Contributors Guide
Style Guide
Lua API
Dev Tips
BitStream
CAccountPassword
Debug Settings
General
Testing Lua
Dependencies
MTADiag
Future Planning
CEF Versions
Windows XP Support
Things for 1.6