mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-25 16:40:15 +00:00
Add string.len to base library
This commit is contained in:
parent
ce844dc110
commit
8b931fa4a7
@ -510,13 +510,25 @@ int cosmoB_sChar(CState *state, int nargs, CValue *args) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cosmoB_sLen(CState *state, int nargs, CValue *args) {
|
||||||
|
if (nargs < 1) {
|
||||||
|
cosmoV_error(state, "string.len() expected 1 argument, got %d", nargs);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
cosmoV_pushNumber(state, strlen(cosmoO_readCString(cosmoV_readString(args[0]))));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void cosmoB_loadStrLib(CState *state) {
|
void cosmoB_loadStrLib(CState *state) {
|
||||||
const char *identifiers[] = {
|
const char *identifiers[] = {
|
||||||
"sub",
|
"sub",
|
||||||
"find",
|
"find",
|
||||||
"split",
|
"split",
|
||||||
"byte",
|
"byte",
|
||||||
"char"
|
"char",
|
||||||
|
"len"
|
||||||
};
|
};
|
||||||
|
|
||||||
CosmoCFunction strLib[] = {
|
CosmoCFunction strLib[] = {
|
||||||
@ -524,7 +536,8 @@ void cosmoB_loadStrLib(CState *state) {
|
|||||||
cosmoB_sFind,
|
cosmoB_sFind,
|
||||||
cosmoB_sSplit,
|
cosmoB_sSplit,
|
||||||
cosmoB_sByte,
|
cosmoB_sByte,
|
||||||
cosmoB_sChar
|
cosmoB_sChar,
|
||||||
|
cosmoB_sLen
|
||||||
};
|
};
|
||||||
|
|
||||||
// make string library object
|
// make string library object
|
||||||
|
Loading…
Reference in New Issue
Block a user