mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2026-07-24 20:12:42 +00:00
Codechange: put SQRegFunctions into initializer_list and use ranged for loops
This commit is contained in:
+6
-9
@@ -67,7 +67,7 @@ SINGLE_ARG_FUNC(ceil, 1)
|
||||
SINGLE_ARG_FUNC(exp, 100)
|
||||
|
||||
#define _DECL_FUNC(name,nparams,tycheck) {#name,math_##name,nparams,tycheck}
|
||||
static SQRegFunction mathlib_funcs[] = {
|
||||
static const std::initializer_list<SQRegFunction> mathlib_funcs = {
|
||||
_DECL_FUNC(sqrt,2,".n"),
|
||||
_DECL_FUNC(sin,2,".n"),
|
||||
_DECL_FUNC(cos,2,".n"),
|
||||
@@ -88,7 +88,6 @@ static SQRegFunction mathlib_funcs[] = {
|
||||
#endif /* EXPORT_DEFAULT_SQUIRREL_FUNCTIONS */
|
||||
_DECL_FUNC(fabs,2,".n"),
|
||||
_DECL_FUNC(abs,2,".n"),
|
||||
{nullptr,nullptr,0,nullptr},
|
||||
};
|
||||
|
||||
#ifndef M_PI
|
||||
@@ -97,14 +96,12 @@ static SQRegFunction mathlib_funcs[] = {
|
||||
|
||||
SQRESULT sqstd_register_mathlib(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger i=0;
|
||||
while(mathlib_funcs[i].name!=nullptr) {
|
||||
sq_pushstring(v,mathlib_funcs[i].name);
|
||||
sq_newclosure(v,mathlib_funcs[i].f,0);
|
||||
sq_setparamscheck(v,mathlib_funcs[i].nparamscheck,mathlib_funcs[i].typemask);
|
||||
sq_setnativeclosurename(v,-1,mathlib_funcs[i].name);
|
||||
for(auto &func : mathlib_funcs) {
|
||||
sq_pushstring(v,func.name);
|
||||
sq_newclosure(v,func.f,0);
|
||||
sq_setparamscheck(v,func.nparamscheck,func.typemask);
|
||||
sq_setnativeclosurename(v,-1,func.name);
|
||||
sq_createslot(v,-3);
|
||||
i++;
|
||||
}
|
||||
#ifdef EXPORT_DEFAULT_SQUIRREL_FUNCTIONS
|
||||
sq_pushstring(v,"RAND_MAX");
|
||||
|
||||
Reference in New Issue
Block a user