本文整理汇总了C++中call_binTM函数的典型用法代码示例。如果您正苦于以下问题:C++ call_binTM函数的具体用法?C++ call_binTM怎么用?C++ call_binTM使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了call_binTM函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: luaV_concat
void luaV_concat (lua_State *L, int total, int last) {
do {
StkId top = L->base + last + 1;
int n = 2; /* number of elements handled in this pass (at least 2) */
if (!tostring(L, top-2) || !tostring(L, top-1)) {
if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
luaG_concaterror(L, top-2, top-1);
} else if (tsvalue(top-1)->tsv.len > 0) { /* if len=0, do nothing */
/* at least two string values; get as many as possible */
lu_mem tl = cast(lu_mem, tsvalue(top-1)->tsv.len) +
cast(lu_mem, tsvalue(top-2)->tsv.len);
char *buffer;
int i;
while (n < total && tostring(L, top-n-1)) { /* collect total length */
tl += tsvalue(top-n-1)->tsv.len;
n++;
}
if (tl > MAX_SIZET) luaG_runerror(L, "string size overflow");
buffer = luaZ_openspace(L, &G(L)->buff, tl);
tl = 0;
for (i=n; i>0; i--) { /* concat all strings */
size_t l = tsvalue(top-i)->tsv.len;
memcpy(buffer+tl, svalue(top-i), l);
tl += l;
}
setsvalue2s(top-n, luaS_newlstr(L, buffer, tl));
}
total -= n-1; /* got `n' strings to create 1 new */
last -= n-1;
} while (total > 1); /* repeat until only 1 result left */
}
开发者ID:Falcon-peregrinus,项目名称:angband-russian,代码行数:31,代码来源:lvm.c
示例2: call_orderTM
static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2,
TMS event) {
if (!call_binTM(L, p1, p2, L->top, event))
return -1; /* no metamethod */
else
return !l_isfalse(L->top);
}
开发者ID:lriki,项目名称:Volkoff,代码行数:7,代码来源:lvm.c
示例3: Arith
static void Arith (lua_State *L, StkId ra, const TValue *rb,
const TValue *rc, TMS op) {
TValue tempb, tempc;
const TValue *b, *c;
if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
(c = luaV_tonumber(rc, &tempc)) != NULL) {
lua_Number nb = nvalue(b), nc = nvalue(c);
switch (op) {
case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break;
case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break;
case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break;
case TM_DIV: setnvalue(ra, luai_lnumdiv(nb, nc)); break;
case TM_MOD: setnvalue(ra, luai_lnummod(nb, nc)); break;
case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break;
case TM_UNM: setnvalue(ra, luai_numunm(nb)); break;
default: lua_assert(0); break;
}
}
else {
ptrdiff_t br = savestack(L, rb);
ptrdiff_t cr = savestack(L, rc);
if (!call_binTM(L, rb, rc, ra, op)) {
luaG_aritherror(L, restorestack(L, br), restorestack(L, cr));
}
}
}
开发者ID:Nicholas3388,项目名称:LuaNode,代码行数:26,代码来源:lvm.c
示例4: luaV_concat
// [@ltm] 对参数栈上的参数执行concat操作
// total 需要concat的参数的个数
// last concat的数组最后一个元素下标
void luaV_concat (lua_State *L, int total, int last) {
do {
StkId top = L->base + last + 1;
int n = 2; /* number of elements handled in this pass (at least 2) */
if (!tostring(L, top-2) || !tostring(L, top-1)) {
// 两个参数不全都是string,所以只能通过metamethod来处理
if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
luaG_concaterror(L, top-2, top-1);
} else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing<优化的套路呀> */
/* at least two string values; get as many as possible */
size_t tl = tsvalue(top-1)->len;
char *buffer;
int i;
/* collect total length */
for (n = 1; n < total && tostring(L, top-n-1); n++) {
size_t l = tsvalue(top-n-1)->len;
if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow");
tl += l;
}
// 这里保存了要concat的string的总大小
buffer = luaZ_openspace(L, &G(L)->buff, tl);
tl = 0;
for (i=n; i>0; i--) { /* concat all strings */
size_t l = tsvalue(top-i)->len;
memcpy(buffer+tl, svalue(top-i), l);
tl += l;
}
setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
}
total -= n-1; /* got `n' strings to create 1 new */
last -= n-1;
} while (total > 1); /* repeat until only 1 result left */
}
开发者ID:anod221,项目名称:Lua51SourceCodeNote,代码行数:36,代码来源:lvm.c
示例5: luaV_strconc
void luaV_strconc (lua_State *L, int total, StkId top) {
do {
int n = 2; /* number of elements handled in this pass (at least 2) */
if (tostring(L, top-2) || tostring(L, top-1)) {
if (!call_binTM(L, top, TM_CONCAT))
luaG_binerror(L, top-2, LUA_TSTRING, "concat");
}
else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */
/* at least two string values; get as many as possible */
lint32 tl = (lint32)tsvalue(top-1)->len +
(lint32)tsvalue(top-2)->len;
char *buffer;
int i;
while (n < total && !tostring(L, top-n-1)) { /* collect total length */
tl += tsvalue(top-n-1)->len;
n++;
}
if (tl > MAX_SIZET) lua_error(L, "string size overflow");
buffer = luaO_openspace(L, tl);
tl = 0;
for (i=n; i>0; i--) { /* concat all strings */
size_t l = tsvalue(top-i)->len;
memcpy(buffer+tl, tsvalue(top-i)->str, l);
tl += l;
}
tsvalue(top-n) = luaS_newlstr(L, buffer, tl);
}
total -= n-1; /* got `n' strings to create 1 new */
top -= n-1;
} while (total > 1); /* repeat until only 1 result left */
}
开发者ID:jcubic,项目名称:ToME,代码行数:31,代码来源:lvm.c
示例6: luaV_concat
void luaV_concat (lua_State *L, int total, int last) {
do {
StkId top = L->base + last + 1;
int n = 2; /* number of elements handled in this pass (at least 2) */
if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {
if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
luaG_concaterror(L, top-2, top-1);
} else if (tsvalue(top-1)->len == 0) /* second op is empty? */
(void)tostring(L, top - 2); /* result is first op (as string) */
else {
/* at least two string values; get as many as possible */
size_t tl = tsvalue(top-1)->len;
char *buffer;
int i;
/* collect total length */
for (n = 1; n < total && tostring(L, top-n-1); n++) {
size_t l = tsvalue(top-n-1)->len;
if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow");
tl += l;
}
buffer = luaZ_openspace(L, &G(L)->buff, tl);
tl = 0;
for (i=n; i>0; i--) { /* concat all strings */
size_t l = tsvalue(top-i)->len;
memcpy(buffer+tl, svalue(top-i), l);
tl += l;
}
setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
}
total -= n-1; /* got `n' strings to create 1 new */
last -= n-1;
} while (total > 1); /* repeat until only 1 result left */
}
开发者ID:03050903,项目名称:Urho3D,代码行数:33,代码来源:lvm.c
示例7: Arith
static void Arith (lua_State *L, StkId ra,
const TObject *rb, const TObject *rc, TMS op) {
TObject tempb, tempc;
const TObject *b, *c;
if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
(c = luaV_tonumber(rc, &tempc)) != NULL) {
switch (op) {
case TM_ADD: setnvalue(ra, nvalue(b) + nvalue(c)); break;
case TM_SUB: setnvalue(ra, nvalue(b) - nvalue(c)); break;
case TM_MUL: setnvalue(ra, nvalue(b) * nvalue(c)); break;
case TM_DIV: setnvalue(ra, nvalue(b) / nvalue(c)); break;
case TM_POW: {
const TObject *f = luaH_getstr(hvalue(gt(L)), G(L)->tmname[TM_POW]);
ptrdiff_t res = savestack(L, ra);
if (!ttisfunction(f))
luaG_runerror(L, "`__pow' (`^' operator) is not a function");
callTMres(L, f, b, c);
ra = restorestack(L, res); /* previous call may change stack */
setobjs2s(ra, L->top);
break;
}
default: lua_assert(0); break;
}
}
else if (!call_binTM(L, rb, rc, ra, op))
luaG_aritherror(L, rb, rc);
}
开发者ID:Falcon-peregrinus,项目名称:angband-russian,代码行数:27,代码来源:lvm.c
示例8: luaV_arith
void luaV_arith (lua_State *L, StkId ra, const TValue *rb,
const TValue *rc, TMS op) {
TValue tempb, tempc;
const TValue *b, *c;
if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
(c = luaV_tonumber(rc, &tempc)) != NULL) {
lua_Number res = luaO_arith(op - TM_ADD + LUA_OPADD, nvalue(b), nvalue(c));
setnvalue(ra, res);
}
else if (!call_binTM(L, rb, rc, ra, op))
luaG_aritherror(L, rb, rc);
}
开发者ID:lriki,项目名称:Volkoff,代码行数:12,代码来源:lvm.c
示例9: luaV_lessthan
int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r, StkId top) {
if (ttype(l) == LUA_TNUMBER && ttype(r) == LUA_TNUMBER)
return (nvalue(l) < nvalue(r));
else if (ttype(l) == LUA_TSTRING && ttype(r) == LUA_TSTRING)
return (luaV_strcomp(tsvalue(l), tsvalue(r)) < 0);
else { /* call TM */
luaD_checkstack(L, 2);
*top++ = *l;
*top++ = *r;
if (!call_binTM(L, top, TM_LT))
luaG_ordererror(L, top-2);
L->top--;
return (ttype(L->top) != LUA_TNIL);
}
}
开发者ID:uvbs,项目名称:wx2Server,代码行数:15,代码来源:lvm.c
示例10: comparison
static void comparison(lua_Type ttype_less, lua_Type ttype_equal, lua_Type ttype_great, IMS op) {
Stack *S = &lua_state->stack;
TObject *l = S->top-2;
TObject *r = S->top-1;
int32 result;
if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER)
result = (nvalue(l) < nvalue(r)) ? -1 : (nvalue(l) == nvalue(r)) ? 0 : 1;
else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING)
result = strcoll(svalue(l), svalue(r));
else {
call_binTM(op, "unexpected type in comparison");
return;
}
S->top--;
nvalue(S->top - 1) = 1;
ttype(S->top - 1) = (result < 0) ? ttype_less : (result == 0) ? ttype_equal : ttype_great;
}
开发者ID:Templier,项目名称:residual,代码行数:17,代码来源:lvm.cpp
示例11: luaV_concat
void luaV_concat (lua_State *L, int total, int last) {
lu_mem max_sizet = MAX_SIZET;
if (G(L)->memlimit < max_sizet) max_sizet = G(L)->memlimit;
do {
/* Any call which does a memory allocation may trim the stack,
invalidating top unless the stack is fixed duri ng the allocation */
StkId top = L->base + last + 1;
fixedstack(L);
int n = 2; /* number of elements handled in this pass (at least 2) */
if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {
unfixedstack(L);
if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) {
/* restore 'top' pointer, since stack might have been reallocted */
top = L->base + last + 1;
luaG_concaterror(L, top-2, top-1);
}
} else if (tsvalue(top-1)->len == 0) { /* second op is empty? */
(void)tostring(L, top - 2); /* result is first op (as string) */
} else {
/* at least two string values; get as many as possible */
size_t tl = tsvalue(top-1)->len;
char *buffer;
int i;
/* collect total length */
for (n = 1; n < total && tostring(L, top-n-1); n++) {
size_t l = tsvalue(top-n-1)->len;
if (l >= max_sizet - tl) luaG_runerror(L, "string length overflow");
tl += l;
}
G(L)->buff.n = tl;
buffer = luaZ_openspace(L, &G(L)->buff, tl);
tl = 0;
for (i=n; i>0; i--) { /* concat all strings */
size_t l = tsvalue(top-i)->len;
c_memcpy(buffer+tl, svalue(top-i), l);
tl += l;
}
setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
luaZ_resetbuffer(&G(L)->buff);
}
total -= n-1; /* got `n' strings to create 1 new */
last -= n-1;
unfixedstack(L);
} while (total > 1); /* repeat until only 1 result left */
}
开发者ID:Dxploto,项目名称:nodemcu-firmware,代码行数:45,代码来源:lvm.c
示例12: comparison
static void comparison (lua_Type ttype_less, lua_Type ttype_equal,
lua_Type ttype_great, IMS op)
{
TObject *l = top-2;
TObject *r = top-1;
int result;
if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER)
result = (nvalue(l) < nvalue(r)) ? -1 : (nvalue(l) == nvalue(r)) ? 0 : 1;
else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING)
result = strcmp(svalue(l), svalue(r));
else {
call_binTM(op, "unexpected type at comparison");
return;
}
top--;
nvalue(top-1) = 1;
ttype(top-1) = (result < 0) ? ttype_less :
(result == 0) ? ttype_equal : ttype_great;
}
开发者ID:Akagi201,项目名称:learning-lua,代码行数:19,代码来源:opcode.c
示例13: luaV_concat
void luaV_concat (lua_State *L, int total) {
lua_assert(total >= 2);
do {
StkId top = L->top;
int n = 2; /* number of elements handled in this pass (at least 2) */
if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {
if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
luaG_concaterror(L, top-2, top-1);
}
else if (tsvalue(top-1)->len == 0) /* second operand is empty? */
(void)tostring(L, top - 2); /* result is first operand */
else if (ttisstring(top-2) && tsvalue(top-2)->len == 0) {
setsvalue2s(L, top-2, rawtsvalue(top-1)); /* result is second op. */
}
else {
/* at least two non-empty string values; get as many as possible */
size_t tl = tsvalue(top-1)->len;
char *buffer;
int i;
/* collect total length */
for (i = 1; i < total && tostring(L, top-i-1); i++) {
size_t l = tsvalue(top-i-1)->len;
if (l >= (MAX_SIZET/sizeof(char)) - tl)
luaG_runerror(L, "string length overflow");
tl += l;
}
buffer = luaZ_openspace(L, &G(L)->buff, tl);
tl = 0;
n = i;
do { /* concat all strings */
size_t l = tsvalue(top-i)->len;
memcpy(buffer+tl, svalue(top-i), l * sizeof(char));
tl += l;
} while (--i > 0);
setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
}
total -= n-1; /* got 'n' strings to create 1 new */
L->top -= n-1; /* popped 'n' strings and pushed one */
} while (total > 1); /* repeat until only 1 result left */
}
开发者ID:lriki,项目名称:Volkoff,代码行数:40,代码来源:lvm.c
示例14: Logic
static void Logic (lua_State *L, StkId ra, const TValue *rb,
const TValue *rc, TMS op) {
TValue tempb, tempc;
const TValue *b, *c;
if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
(c = luaV_tonumber(rc, &tempc)) != NULL) {
lua_Number nb = nvalue(b), nc = nvalue(c);
lua_Integer r;
switch (op) {
case TM_BLSHFT: luai_loglshft(r, nb, nc); break;
case TM_BRSHFT: luai_logrshft(r, nb, nc); break;
case TM_BOR: luai_logor(r, nb, nc); break;
case TM_BAND: luai_logand(r, nb, nc); break;
case TM_BXOR: luai_logxor(r, nb, nc); break;
case TM_BNOT: luai_lognot(r, nb); break;
default: lua_assert(0); r = 0; break;
}
setnvalue(ra, r);
}
else if (!call_binTM(L, rb, rc, ra, op))
luaG_logicerror(L, rb, rc);
}
开发者ID:DaveCausey,项目名称:xenon,代码行数:22,代码来源:lvm.c
示例15: Arith
static void Arith (lua_State *L, StkId ra, const TValue *rb,
const TValue *rc, TMS op) {
TValue tempb, tempc;
const TValue *b, *c;
if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
(c = luaV_tonumber(rc, &tempc)) != NULL) {
lua_Number nb = nvalue(b), nc = nvalue(c);
switch (op) {
case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break;
case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break;
case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break;
case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break;
case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break;
case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break;
case TM_UNM: setnvalue(ra, luai_numunm(nb)); break;
#if defined(LUA_BITWISE_OPERATORS)
case TM_INTDIV: setnvalue(ra, luai_numintdiv(nb, nc)); break;
#endif
default: lua_assert(0); break;
}
}
else if (!call_binTM(L, rb, rc, ra, op))
luaG_aritherror(L, rb, rc);
}
开发者ID:DaveCausey,项目名称:xenon,代码行数:24,代码来源:lvm.c
示例16: luaV_execute
//.........这里部分代码省略.........
Protect(luaV_gettable(L, rb, RKC(i), ra));
continue;
}
case OP_ADD: {
arith_op(luai_numadd, TM_ADD);
continue;
}
case OP_SUB: {
arith_op(luai_numsub, TM_SUB);
continue;
}
case OP_MUL: {
arith_op(luai_nummul, TM_MUL);
continue;
}
case OP_DIV: {
arith_op(luai_numdiv, TM_DIV);
continue;
}
case OP_MOD: {
arith_op(luai_nummod, TM_MOD);
continue;
}
case OP_POW: {
arith_op(luai_numpow, TM_POW);
continue;
}
case OP_UNM: {
TValue *rb = RB(i);
if (ttisnumber(rb)) {
lua_Number nb = nvalue(rb);
setnvalue(ra, luai_numunm(nb));
}
else {
Protect(luaV_arith(L, ra, rb, rb, TM_UNM));
}
continue;
}
case OP_NOT: {
int res = l_isfalse(RB(i)); /* next assignment may change this value */
setbvalue(ra, res);
continue;
}
case OP_LEN: {
const TValue *rb = RB(i);
switch (ttype(rb)) {
case LUA_TTABLE: {
setnvalue(ra, cast_num(luaH_getn(hvalue(rb))));
break;
}
case LUA_TSTRING: {
setnvalue(ra, cast_num(tsvalue(rb)->len));
break;
}
default: { /* try metamethod */
Protect(
if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN))
luaG_typeerror(L, rb, "get length of");
)
}
}
continue;
}
case OP_CONCAT: {
int b = GETARG_B(i);
int c = GETARG_C(i);
Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L));
setobjs2s(L, RA(i), base+b);
continue;
}
case OP_JMP: {
dojump(L, pc, GETARG_sBx(i));
continue;
}
case OP_EQ: {
TValue *rb = RKB(i);
TValue *rc = RKC(i);
Protect(
if (equalobj(L, rb, rc) == GETARG_A(i))
dojump(L, pc, GETARG_sBx(*pc));
)
pc++;
continue;
}
case OP_LT: {
Protect(
if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i))
dojump(L, pc, GETARG_sBx(*pc));
)
pc++;
continue;
}
case OP_LE: {
Protect(
if (luaV_lessequal(L, RKB(i), RKC(i)) == GETARG_A(i))
dojump(L, pc, GETARG_sBx(*pc));
)
pc++;
continue;
}
开发者ID:angryzor,项目名称:luajit-tilepro64,代码行数:101,代码来源:lvm.c
示例17: luaV_execute
//.........这里部分代码省略.........
ttype(top) = LUA_TNUMBER;
nvalue(top) = (Number)GETARG_S(i);
call_arith(L, top+1, TM_ADD);
}
else
nvalue(top-1) += (Number)GETARG_S(i);
break;
}
case OP_SUB: {
if (tonumber(top-2) || tonumber(top-1))
call_arith(L, top, TM_SUB);
else
nvalue(top-2) -= nvalue(top-1);
top--;
break;
}
case OP_MULT: {
if (tonumber(top-2) || tonumber(top-1))
call_arith(L, top, TM_MUL);
else
nvalue(top-2) *= nvalue(top-1);
top--;
break;
}
case OP_DIV: {
if (tonumber(top-2) || tonumber(top-1))
call_arith(L, top, TM_DIV);
else
nvalue(top-2) /= nvalue(top-1);
top--;
break;
}
case OP_POW: {
if (!call_binTM(L, top, TM_POW))
lua_error(L, "undefined operation");
top--;
break;
}
case OP_CONCAT: {
int n = GETARG_U(i);
luaV_strconc(L, n, top);
top -= n-1;
L->top = top;
luaC_checkGC(L);
break;
}
case OP_MINUS: {
if (tonumber(top-1)) {
ttype(top) = LUA_TNIL;
call_arith(L, top+1, TM_UNM);
}
else
nvalue(top-1) = -nvalue(top-1);
break;
}
case OP_NOT: {
ttype(top-1) =
(ttype(top-1) == LUA_TNIL) ? LUA_TNUMBER : LUA_TNIL;
nvalue(top-1) = 1;
break;
}
case OP_JMPNE: {
top -= 2;
if (!luaO_equalObj(top, top+1)) dojump(pc, i);
break;
}
开发者ID:uvbs,项目名称:wx2Server,代码行数:67,代码来源:lvm.c
示例18: call_arith
static void call_arith (lua_State *L, StkId top, TMS event) {
if (!call_binTM(L, top, event))
luaG_binerror(L, top-2, LUA_TNUMBER, "perform arithmetic on");
}
开发者ID:uvbs,项目名称:wx2Server,代码行数:4,代码来源:lvm.c
示例19: call_arith
static void call_arith (IMS event)
{
call_binTM(event, "unexpected type in arithmetic operation");
}
开发者ID:Botje,项目名称:residualvm-tools,代码行数:4,代码来源:lvm.cpp
示例20: Arith
/* Note: if called for unary operations, 'rc'=='rb'.
*/
static void Arith (lua_State *L, StkId ra, const TValue *rb,
const TValue *rc, TMS op) {
TValue tempb, tempc;
const TValue *b, *c;
lua_Number nb,nc;
if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
(c = luaV_tonumber(rc, &tempc)) != NULL) {
/* Keep integer arithmetics in the integer realm, if possible.
*/
#ifdef LUA_TINT
if (ttisint(b) && ttisint(c)) {
lua_Integer ib = ivalue(b), ic = ivalue(c);
lua_Integer *ri = &ra->value.i;
ra->tt= LUA_TINT; /* part of 'setivalue(ra)' */
switch (op) {
case TM_ADD: if (try_addint( ri, ib, ic)) return; break;
case TM_SUB: if (try_subint( ri, ib, ic)) return; break;
case TM_MUL: if (try_mulint( ri, ib, ic)) return; break;
case TM_DIV: if (try_divint( ri, ib, ic)) return; break;
case TM_MOD: if (try_modint( ri, ib, ic)) return; break;
case TM_POW: if (try_powint( ri, ib, ic)) return; break;
case TM_UNM: if (try_unmint( ri, ib)) return; break;
default: lua_assert(0);
}
}
#endif
/* Fallback to floating point, when leaving range. */
#ifdef LNUM_COMPLEX
if ((nvalue_img(b)!=0) || (nvalue_img(c)!=0)) {
lua_Complex r;
if (op==TM_UNM) {
r= -nvalue_complex_fast(b); /* never an integer (or scalar) */
setnvalue_complex_fast( ra, r );
} else {
lua_Complex bb= nvalue_complex(b), cc= nvalue_complex(c);
switch (op) {
case TM_ADD: r= bb + cc; break;
case TM_SUB: r= bb - cc; break;
case TM_MUL: r= bb * cc; break;
case TM_DIV: r= bb / cc; break;
case TM_MOD:
luaG_runerror(L, "attempt to use %% on complex numbers"); /* no return */
case TM_POW: r= luai_vectpow( bb, cc ); break;
default: lua_assert(0); r=0;
}
setnvalue_complex( ra, r );
}
return;
}
#endif
nb = nvalue(b); nc = nvalue(c);
switch (op) {
case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); return;
case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); return;
case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); return;
case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); return;
case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); return;
case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); return;
case TM_UNM: setnvalue(ra, luai_numunm(nb)); return;
default: lua_assert(0);
}
}
/* Either operand not a number */
if (!call_binTM(L, rb, rc, ra, op))
luaG_aritherror(L, rb, rc);
}
开发者ID:JDuverge,项目名称:windirstat,代码行数:72,代码来源:lvm.c
注:本文中的call_binTM函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论