本文整理汇总了C++中posrelat函数的典型用法代码示例。如果您正苦于以下问题:C++ posrelat函数的具体用法?C++ posrelat怎么用?C++ posrelat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了posrelat函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: str_byte
static int str_byte (lua_State *L) {
size_t l;
const char *s = luaL_checklstring(L, 1, &l);
sint32 pos = posrelat(luaL_optlong(L, 2, 1), l);
if (pos <= 0 || (size_t)(pos) > l) /* index out of range? */
return 0; /* no answer */
lua_pushnumber(L, uchar(s[pos-1]));
return 1;
}
开发者ID:Darkhunter,项目名称:Tranquillien-HCRP-Project-using-NeL,代码行数:9,代码来源:lstrlib.c
示例2: str_byte
static int str_byte (lua_State *L)
{
size_t l;
const char *s = luaL_checklstring(L, 1, &l);
ptrdiff_t posi = posrelat(luaL_optinteger(L, 2, 1), l);
ptrdiff_t pose = posrelat(luaL_optinteger(L, 3, posi), l);
int n, i;
if (posi <= 0) posi = 1;
if ((size_t)pose > l) pose = l;
if (posi > pose) return 0; /* empty interval; return no values */
n = (int)(pose - posi + 1);
if (posi + n <= pose) /* overflow? */
luaL_error(L, "string slice too long");
luaL_checkstack(L, n, "string slice too long");
for (i=0; i<n; i++)
lua_pushinteger(L, uchar(s[posi+i-1]));
return n;
}
开发者ID:Amalinda,项目名称:ruuvitracker_fw,代码行数:18,代码来源:lstrlib.c
示例3: str_find_aux
static int str_find_aux (LuaMatchState *ms, int find, const char *s, size_t ls,
const char *p, size_t lp, size_t init, int raw_find) {
int result = 0; /* not found */
ms->error = NULL;
init = posrelat(init, ls);
if (init < 0) init = 0;
else if (init > ls + 1) { /* start after string's end? */
return 0; /* cannot find anything */
}
/* explicit request or no special characters? */
if (find && (raw_find || nospecials(p, lp))) {
/* do a plain search */
const char *s2 = lmemfind(s + init, ls - init + 1, p, lp);
if (s2) {
int start_pos = ((int)(s2 - s));
ms->level = 1;
ms->capture[0].len = CAP_POSITION;
ms->capture[0].init = (const char *)start_pos;
result = start_pos + lp;
}
}
else {
const char *s1 = s + init;
int anchor = (*p == '^');
if (anchor) {
p++; lp--; /* skip anchor character */
}
ms->src_init = s;
ms->src_end = s + ls;
ms->p_end = p + lp;
do {
const char *res;
ms->level = 0;
if ((res=match(ms, s1, p)) != NULL) {
result = (int)(res - s);
goto eofunc;
}
} while (s1++ < ms->src_end && !anchor);
}
eofunc:
if(result){
int i;
for(i=0; i<ms->level; ++i){
if(ms->capture[i].len == CAP_UNFINISHED){
ms->error = "unfinished capture";
return 0;
}
}
}
return result;
}
开发者ID:mingodad,项目名称:lua-regex-standalone,代码行数:53,代码来源:lua-regex.c
示例4: str_find_aux
static int str_find_aux (lua_State *L, int find) {
size_t ls, lp;
const char *s = luaL_checklstring(L, 1, &ls);
const char *p = luaL_checklstring(L, 2, &lp);
size_t init = posrelat(luaL_optinteger(L, 3, 1), ls);
if (init < 1) init = 1;
else if (init > ls + 1) { /* start after string's end? */
lua_pushnil(L); /* cannot find anything */
return 1;
}
/* explicit request or no special characters? */
if (find && (lua_toboolean(L, 4) || nospecials(p, lp))) {
/* do a plain search */
const char *s2 = lmemfind(s + init - 1, ls - init + 1, p, lp);
if (s2) {
lua_pushinteger(L, s2 - s + 1);
lua_pushinteger(L, s2 - s + lp);
return 2;
}
}
else {
MatchState ms;
const char *s1 = s + init - 1;
int anchor = (*p == '^');
if (anchor) {
p++; lp--; /* skip anchor character */
}
ms.L = L;
ms.matchdepth = MAXCCALLS;
ms.src_init = s;
ms.src_end = s + ls;
ms.p_end = p + lp;
do {
const char *res;
ms.level = 0;
lua_assert(ms.matchdepth == MAXCCALLS);
if ((res=match(&ms, s1, p)) != NULL) {
if (find) {
lua_pushinteger(L, s1 - s + 1); /* start */
lua_pushinteger(L, res - s); /* end */
return push_captures(&ms, NULL, 0) + 2;
}
else
return push_captures(&ms, s1, res);
}
} while (s1++ < ms.src_end && !anchor);
}
lua_pushnil(L); /* not found */
return 1;
}
开发者ID:dgkang,项目名称:skynet_v0.1_with_notes,代码行数:50,代码来源:lstrlib.c
示例5: t_slice
static int t_slice (lua_State *L) {
int n = aux_getn(L, 1);
int start = posrelat(luaL_checkint(L, 2), n);
int end = posrelat(luaL_optint(L, 3, -1), n);
int skip = luaL_optint(L, 4, 1);
luaL_argcheck(L, skip != 0, 4, "step argument must not be zero");
if (start < 1) start = 1;
if (end > n) end = n;
int i, ni;
if (skip > 0)
ni = (end >= start) ? ((end - start) / skip) + 1 : 0;
else /* skip < 0 */
ni = (start >= end) ? ((start - end) / -skip) + 1 : 0;
lua_createtable(L, ni, 0);
for (i = 1; i <= ni; ++i) {
lua_rawgeti(L, 1, start);
lua_rawseti(L, -2, i);
start += skip;
}
return 1;
}
开发者ID:whoopdedo,项目名称:lgscript,代码行数:23,代码来源:lext.c
示例6: lhc_buffer_set
static int lhc_buffer_set(lua_State *L)
{
float *buf = lhc_checkbuffer(L, 1);
size_t size = lhc_buffer_nsamples(L, 1);
size_t pos = posrelat(luaL_checkinteger(L, 2), size);
float val = luaL_checknumber(L, 3);
if (pos < 1 || pos > size)
return luaL_error(L, "Index out of bounds: %lu", pos);
buf[pos-1] = val;
lua_settop(L, 1);
return 1;
}
开发者ID:vrld,项目名称:LHC,代码行数:15,代码来源:buffer.c
示例7: lhc_buffer_get
/* check implementation of str_byte in lua sourcecode, lstrlib.c:110 */
static int lhc_buffer_get(lua_State *L)
{
float *buf = lhc_checkbuffer(L, 1);
size_t size = lhc_buffer_nsamples(L, 1);
size_t posi = posrelat(luaL_checkinteger(L, 2), size);
size_t pose = posrelat(luaL_optinteger(L, 3, posi), size);
if (posi <= 0)
posi = 1;
if (pose > size)
pose = size;
if (posi > pose)
return 0;
int n = (int)(pose - posi + 1);
luaL_checkstack(L, n, "buffer slice too long");
for (size_t i = posi; i <= pose; ++i)
lua_pushnumber(L, buf[i - 1]);
return n;
}
开发者ID:vrld,项目名称:LHC,代码行数:25,代码来源:buffer.c
示例8: lhc_buffer_map
static int lhc_buffer_map(lua_State *L)
{
float *buf = lhc_checkbuffer(L, 1);
size_t size = lhc_buffer_nsamples(L, 1);
size_t posi = 0, pose = size;
int stackpos_function = 2;
if (lua_isnumber(L, 2))
{
posi = posrelat(lua_tointeger(L, 2), size);
stackpos_function = 3;
}
if (lua_isnumber(L, 3))
{
pose = posrelat(lua_tointeger(L, 3), size);
stackpos_function = 4;
}
if (!lua_isfunction(L, stackpos_function))
return luaL_typerror(L, stackpos_function, "function");
for (; posi <= pose; ++posi)
{
lua_pushvalue(L, stackpos_function);
lua_pushinteger(L, posi);
lua_pushnumber(L, buf[posi-1]);
lua_call(L, 2, 1);
buf[posi-1] = lua_tonumber(L, -1);
lua_pop(L, 1);
}
lua_settop(L, 1);
return 1;
}
开发者ID:vrld,项目名称:LHC,代码行数:36,代码来源:buffer.c
示例9: gfind_aux
//mod by nirenr
static int gfind_aux (lua_State *L) {
size_t ls, lp;
const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls);
const char *p = lua_tolstring(L, lua_upvalueindex(2), &lp);
lua_Integer init = posrelat(luaL_optinteger(L, lua_upvalueindex(3), 1), ls);
if (init < 1) init = 1;
else if (init > (lua_Integer)ls + 1) { /* start after string's end? */
return 0; /* cannot find anything */
}
/* explicit request or no special characters? */
if (lua_toboolean(L, lua_upvalueindex(4)) || nospecials(p, lp)) {
/* do a plain search */
const char *s2 = lmemfind(s + init - 1, ls - (size_t)init + 1, p, lp);
if (s2) {
lua_pushinteger(L, (s2 - s) + 1);
lua_pushinteger(L, (s2 - s) + lp);
lua_pushinteger(L,(s2 - s) + lp + 1);
lua_replace(L, lua_upvalueindex(3));
return 2;
}
}
else {
MatchState ms;
const char *s1 = s + init - 1;
int anchor = (*p == '^');
if (anchor) {
p++; lp--; /* skip anchor character */
}
ms.L = L;
ms.matchdepth = MAXCCALLS;
ms.src_init = s;
ms.src_end = s + ls;
ms.p_end = p + lp;
do {
const char *res;
ms.level = 0;
lua_assert(ms.matchdepth == MAXCCALLS);
if ((res=match(&ms, s1, p)) != NULL) {
lua_pushinteger(L, (s1 - s) + 1); /* start */
lua_pushinteger(L, res - s); /* end */
lua_pushinteger(L, res - s + 1);
lua_replace(L, lua_upvalueindex(3));
return push_captures(&ms, NULL, 0) + 2;
}
} while (s1++ < ms.src_end && !anchor);
}
return 0; /* not found */
}
开发者ID:cthunter,项目名称:AndroLua_pro,代码行数:49,代码来源:lstrlib.c
示例10: str_find_aux
static int str_find_aux (lua_State *L, int mode) { /* EXT */
size_t ls, lp;
const char *s = luaL_checklstring(L, 1, &ls);
const char *p = luaL_checklstring(L, 2, &lp);
lua_Integer init = posrelat(luaL_optinteger(L, 3, 1), ls);
if (init < 1) init = 1;
else if (init > (lua_Integer)ls + 1) { /* start after string's end? */
lua_pushnil(L); /* cannot find anything */
return 1;
}
/* explicit request or no special characters? */ /* EXT */
if (mode == MODE_FIND && (lua_toboolean(L, 4) || nospecials(p, lp))) {
/* do a plain search */
const char *s2 = lmemfind(s + init - 1, ls - (size_t)init + 1, p, lp);
if (s2) {
lua_pushinteger(L, (s2 - s) + 1);
lua_pushinteger(L, (s2 - s) + lp);
return 2;
}
}
else {
MatchState ms;
const char *s1 = s + init - 1;
int anchor = (*p == '^');
prepstate(&ms, L, s, ls, p, lp); /* EXT (moved before anchor check) */
if (anchor)
p++; /* skip anchor character */ /* EXT */
do {
const char *res;
reprepstate(&ms);
if ((res=match(&ms, s1, p)) != NULL) {
if (mode == MODE_FIND) { /* EXT */
lua_pushinteger(L, (s1 - s) + 1); /* start */
lua_pushinteger(L, res - s); /* end */
return push_captures(&ms, NULL, 0) + 2;
}
else if (mode == MODE_MATCH) /* EXT */
return push_captures(&ms, s1, res);
else { /* EXT */
return build_result_table(&ms, s1, res);
}
}
} while (s1++ < ms.src_end && !anchor);
}
lua_pushnil(L); /* not found */
return 1;
}
开发者ID:jcgoble3,项目名称:lua-matchext,代码行数:47,代码来源:matchext.c
示例11: str_find_aux
static int str_find_aux (lua_State *L, int find) {
size_t l1, l2;
const char *s = luaL_checklstring(L, 1, &l1);
const char *p = luaL_checklstring(L, 2, &l2);
ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1;
if (init < 0) init = 0;
else if ((size_t)(init) > l1) init = (ptrdiff_t)l1;
if (find && (lua_toboolean(L, 4) || /* explicit request? */
strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */
/* do a plain search */
const char *s2 = lmemfind(s+init, l1-init, p, l2);
if (s2) {
lua_pushinteger(L, s2-s+1);
lua_pushinteger(L, s2-s+l2);
return 2;
}
}
else {
MatchState ms;
int anchor = (*p == '^') ? (p++, 1) : 0;
const char *s1=s+init;
ms.L = L;
ms.src_init = s;
ms.src_end = s+l1;
do {
const char *res;
ms.level = 0;
if ((res=match(&ms, s1, p)) != NULL) {
if (find) {
lua_pushinteger(L, s1-s+1); /* start */
lua_pushinteger(L, res-s); /* end */
return push_captures(&ms, NULL, 0) + 2;
}
else
return push_captures(&ms, s1, res);
}
} while (s1++ < ms.src_end && !anchor);
}
lua_pushnil(L); /* not found */
return 1;
}
开发者ID:aronarts,项目名称:FireNET,代码行数:41,代码来源:lstrlib.c
示例12: str_find
static int str_find (lua_State *L) {
size_t l1, l2;
const lua_WChar *s = luaL_checklwstring(L, 1, &l1);
const lua_WChar *p = luaL_checklwstring(L, 2, &l2);
sint32 init = posrelat(luaL_optlong(L, 3, 1), l1) - 1;
luaL_argcheck(L, 0 <= init && (size_t)(init) <= l1, 3, "out of range");
if (lua_toboolean(L, 4) || /* explicit request? */
lua_WChar_pbrk(p, SPECIALS) == NULL) { /* or no special characters? */
/* do a plain search */
const lua_WChar *s2 = lmemfind(s+init, l1-init, p, l2);
if (s2) {
lua_pushnumber(L, s2-s+1);
lua_pushnumber(L, s2-s+l2);
return 2;
}
}
else {
MatchState ms;
int anchor = (*p == '^') ? (p++, 1) : 0;
const lua_WChar *s1=s+init;
ms.L = L;
ms.src_init = s;
ms.src_end = s+l1;
do {
const lua_WChar *res;
ms.level = 0;
if ((res=match(&ms, s1, p)) != NULL) {
lua_pushnumber(L, s1-s+1); /* start */
lua_pushnumber(L, res-s); /* end */
return push_captures(&ms, NULL, 0) + 2;
}
} while (s1++<ms.src_end && !anchor);
}
lua_pushnil(L); /* not found */
return 1;
}
开发者ID:anissen,项目名称:WikiAdventure,代码行数:36,代码来源:lwstrlib.c
示例13: lhc_buffer_insert
static int lhc_buffer_insert(lua_State *L)
{
float *buf = lhc_checkbuffer(L, 1);
size_t size_buf = lhc_buffer_nsamples(L, 1);
size_t posi = posrelat(luaL_checkinteger(L, 2), size_buf);
float *insert = NULL;
size_t size_insert = 0;
int should_free = 0;
int type = lua_type(L, 3);
if (lua_isbuffer(L, 3))
{
insert = (float *)lua_touserdata(L, 3);
size_insert = lhc_buffer_nsamples(L, 3);
}
else if (LUA_TSTRING == type)
{
insert = (float*)lua_tolstring(L, 3, &size_insert);
size_insert /= sizeof(float);
}
else if (LUA_TTABLE == type)
{
should_free = 1;
size_insert = lua_objlen(L, 3);
insert = malloc(size_insert * sizeof(float));
for (size_t i = 0; i < size_insert; ++i)
{
lua_rawgeti(L, 3, i+1);
insert[i] = lua_tonumber(L, -1);
lua_pop(L, 1);
}
}
else if (LUA_TNUMBER == type)
{
should_free = 1;
if (lua_isfunction(L, 4))
{
size_insert = lua_tointeger(L, 3);
insert = malloc(size_insert * sizeof(float));
for (size_t i = 0; i < size_insert; ++i)
{
lua_pushvalue(L, 4);
lua_pushinteger(L, i+posi+1);
lua_call(L, 1, 1);
insert[i] = lua_tonumber(L, -1);
lua_pop(L, 1);
}
}
else
{
size_insert = lua_gettop(L) - 2;
insert = malloc(size_insert * sizeof(float));
for (size_t i = 0; i < size_insert; ++i)
insert[i] = lua_tonumber(L, 3 + i);
}
}
else
return luaL_typerror(L, 3, "buffer or table or string or number");
/* create new buffer using lhc_buffer_new */
size_t size_new = size_buf + size_insert;
lua_pushcfunction(L, lhc_buffer_new);
lua_pushnumber(L, size_new);
lua_call(L, 1, 1);
float *buf_new = (float *)lua_touserdata(L, -1);
size_t pose = posi + size_insert;
for (size_t i = 0; i < size_new; ++i)
{
if (i < posi)
buf_new[i] = buf[i];
else if (i < pose)
buf_new[i] = insert[i - posi];
else
buf_new[i] = buf[i - size_insert];
}
if (should_free)
free(insert);
return 1;
}
开发者ID:vrld,项目名称:LHC,代码行数:82,代码来源:buffer.c
示例14: str_unpack
static int str_unpack (lua_State *L) {
Header h;
const char *fmt = luaL_checkstring(L, 1);
size_t ld;
const char *data = luaL_checklstring(L, 2, &ld);
size_t pos = (size_t)posrelat(luaL_optinteger(L, 3, 1), ld) - 1;
int n = 0; /* number of results */
luaL_argcheck(L, pos <= ld, 3, "initial position out of string");
initheader(L, &h);
while (*fmt != '\0') {
int size, ntoalign;
KOption opt = getdetails(&h, pos, &fmt, &size, &ntoalign);
luaL_argcheck(L, (size_t)ntoalign + size <= ld - pos, 2,
"data string too short");
pos += ntoalign; /* skip alignment */
/* stack space for item + next position */
luaL_checkstack(L, 2, "too many results");
n++;
switch (opt) {
case Kint:
case Kuint: {
lua_Integer res = unpackint(L, data + pos, h.islittle, size,
(opt == Kint));
lua_pushinteger(L, res);
break;
}
case Kfloat: {
volatile Ftypes u;
lua_Number num;
copywithendian(u.buff, data + pos, size, h.islittle);
if (size == sizeof(u.f)) num = (lua_Number)u.f;
else if (size == sizeof(u.d)) num = (lua_Number)u.d;
else num = u.n;
lua_pushnumber(L, num);
break;
}
case Kchar: {
lua_pushlstring(L, data + pos, size);
break;
}
case Kstring: {
size_t len = (size_t)unpackint(L, data + pos, h.islittle, size, 0);
luaL_argcheck(L, len <= ld - pos - size, 2, "data string too short");
lua_pushlstring(L, data + pos + size, len);
pos += len; /* skip string */
break;
}
case Kzstr: {
size_t len = (int)strlen(data + pos);
luaL_argcheck(L, pos + len < ld, 2,
"unfinished string for format 'z'");
lua_pushlstring(L, data + pos, len);
pos += len + 1; /* skip string plus final '\0' */
break;
}
case Kpaddalign: case Kpadding: case Knop:
n--; /* undo increment */
break;
}
pos += size;
}
lua_pushinteger(L, pos + 1); /* next position */
return n + 1;
}
开发者ID:guodawei,项目名称:lua,代码行数:64,代码来源:lstrlib.c
注:本文中的posrelat函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论