Update documentation

This commit is contained in:
BONNAURE Olivier 2024-04-09 17:25:35 +02:00
parent 12b3dfb29c
commit 1f7445ad37
2 changed files with 44 additions and 19 deletions

View file

@ -1062,6 +1062,9 @@ FUNCTIONS
Server Name Indicator (SNI) when performing Fetch() requests.
This function is not available in unsecure mode.
UuidV4() -> str
Returns an uuid v4 string.
Fetch(url:str[,body:str|{method=value:str,body=value:str,headers=table,...}])
├─→ status:int, {header:str=value:str,...}, body:str
└─→ nil, error:str

View file

@ -830,27 +830,49 @@ int LuaVisualizeControlCodes(lua_State *L) {
return LuaCoder(L, VisualizeControlCodes);
}
int LuaUuidV4(lua_State *L) {
char *template = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
char *uuid = (char *)malloc(strlen(template) + 1);
if (uuid == NULL) {
return 0; // Memory allocation failed
}
char v[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
static char uuid_str[37] = {0};
srand(time(NULL));
for (int i = 0; i < strlen(template); i++) {
char c = template[i];
if (c == 'x') {
uuid[i] = (rand() % 16 < 10) ? (rand() % 10 + '0') : (rand() % 6 + 'a');
} else if (c == 'y') {
uuid[i] = (rand() % 4 + '8');
} else {
uuid[i] = c;
}
}
uuid[strlen(template)] = '\0';
lua_pushfstring(L, uuid);
uuid_str[0] = v[rand()%16];
uuid_str[1] = v[rand()%16];
uuid_str[2] = v[rand()%16];
uuid_str[3] = v[rand()%16];
uuid_str[4] = v[rand()%16];
uuid_str[5] = v[rand()%16];
uuid_str[6] = v[rand()%16];
uuid_str[7] = v[rand()%16];
uuid_str[8] = '-';
uuid_str[9] = v[rand()%16];
uuid_str[10] = v[rand()%16];
uuid_str[11] = v[rand()%16];
uuid_str[12] = v[rand()%16];
uuid_str[13] = '-';
uuid_str[14] = '4';
uuid_str[15] = v[rand()%16];
uuid_str[16] = v[rand()%16];
uuid_str[17] = v[rand()%16];
uuid_str[18] = '-';
uuid_str[19] = v[8 + rand()%4];
uuid_str[20] = v[rand()%16];
uuid_str[21] = v[rand()%16];
uuid_str[22] = v[rand()%16];
uuid_str[23] = '-';
uuid_str[24] = v[rand()%16];
uuid_str[25] = v[rand()%16];
uuid_str[26] = v[rand()%16];
uuid_str[27] = v[rand()%16];
uuid_str[28] = v[rand()%16];
uuid_str[29] = v[rand()%16];
uuid_str[30] = v[rand()%16];
uuid_str[31] = v[rand()%16];
uuid_str[32] = v[rand()%16];
uuid_str[33] = v[rand()%16];
uuid_str[34] = v[rand()%16];
uuid_str[35] = v[rand()%16];
uuid_str[36] = '\0';
lua_pushfstring(L, uuid_str);
return 1;
}