MCPcopy Create free account
hub / github.com/DFHack/dfhack / dfhack_random_init

Function dfhack_random_init

library/LuaApi.cpp:1093–1132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1091}
1092
1093static int dfhack_random_init(lua_State *L)
1094{
1095 lua_settop(L, 3);
1096
1097 MersenneRNG *prng = check_random_native(L, 1);
1098
1099 if (lua_isnil(L, 2))
1100 prng->init();
1101 else
1102 {
1103 vector<uint32_t> data;
1104 int tcnt = luaL_optint(L, 3, 1);
1105
1106 if (lua_isnumber(L, 2))
1107 data.push_back(lua_tounsigned(L, 2));
1108 else if (lua_istable(L, 2))
1109 {
1110 int cnt = lua_rawlen(L, 2);
1111 if (cnt <= 0)
1112 luaL_argerror(L, 2, "empty list in dfhack.random.init");
1113
1114 for (int i = 1; i <= cnt; i++)
1115 {
1116 lua_rawgeti(L, 2, i);
1117 if (!lua_isnumber(L, -1))
1118 luaL_argerror(L, 2, "not a number in dfhack.random.init argument");
1119
1120 data.push_back(lua_tounsigned(L, -1));
1121 lua_pop(L, 1);
1122 }
1123 }
1124 else
1125 luaL_argerror(L, 2, "dfhack.random.init argument not number or table");
1126
1127 prng->init(data.data(), data.size(), tcnt);
1128 }
1129
1130 lua_settop(L, 1);
1131 return 1;
1132}
1133
1134static int dfhack_random_new(lua_State *L)
1135{

Callers 1

dfhack_random_newFunction · 0.85

Calls 9

lua_settopFunction · 0.85
check_random_nativeFunction · 0.85
lua_isnumberFunction · 0.85
lua_rawlenFunction · 0.85
luaL_argerrorFunction · 0.85
lua_rawgetiFunction · 0.85
initMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected