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. Server Name Indicator (SNI) when performing Fetch() requests.
This function is not available in unsecure mode. 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,...}]) Fetch(url:str[,body:str|{method=value:str,body=value:str,headers=table,...}])
├─→ status:int, {header:str=value:str,...}, body:str ├─→ status:int, {header:str=value:str,...}, body:str
└─→ nil, error:str └─→ nil, error:str

View file

@ -830,27 +830,49 @@ int LuaVisualizeControlCodes(lua_State *L) {
return LuaCoder(L, VisualizeControlCodes); return LuaCoder(L, VisualizeControlCodes);
} }
int LuaUuidV4(lua_State *L) { int LuaUuidV4(lua_State *L) {
char *template = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"; char v[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
char *uuid = (char *)malloc(strlen(template) + 1); static char uuid_str[37] = {0};
if (uuid == NULL) {
return 0; // Memory allocation failed
}
srand(time(NULL)); uuid_str[0] = v[rand()%16];
uuid_str[1] = v[rand()%16];
for (int i = 0; i < strlen(template); i++) { uuid_str[2] = v[rand()%16];
char c = template[i]; uuid_str[3] = v[rand()%16];
if (c == 'x') { uuid_str[4] = v[rand()%16];
uuid[i] = (rand() % 16 < 10) ? (rand() % 10 + '0') : (rand() % 6 + 'a'); uuid_str[5] = v[rand()%16];
} else if (c == 'y') { uuid_str[6] = v[rand()%16];
uuid[i] = (rand() % 4 + '8'); uuid_str[7] = v[rand()%16];
} else { uuid_str[8] = '-';
uuid[i] = c; uuid_str[9] = v[rand()%16];
} uuid_str[10] = v[rand()%16];
} uuid_str[11] = v[rand()%16];
uuid[strlen(template)] = '\0'; uuid_str[12] = v[rand()%16];
lua_pushfstring(L, uuid); 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; return 1;
} }