static int reportScore(lua_State *L) { GooglePlay *gms = getInstance(L, 1); const char *id = luaL_checkstring(L, 2); long score = luaL_checklong(L, 3); int immediate = lua_toboolean(L, 4); gms->reportScore(id, score, immediate); return 0; }
client_t *client_get_checked_lua(lua_State *L, int idx) { int clientno = luaL_checklong(L, idx); if (clientno < 0 || clientno >= MAXCLIENTS) luaL_error(L, "client number %d out of range", clientno); client_t *client = &clients[clientno]; if (!CLIENT_USED(client)) luaL_error(L, "client %d not in use", clientno); return client; }
int L_msleep(lua_State *L) { uint32_t i; uint32_t n = (uint32_t)luaL_checklong(L, 1); for (i = 0; i < n; i++) { usleep(1000); if (IupLoopStep() == IUP_CLOSE) break; } return 0; }
static int l_easy_setopt_long(lua_State *L) { l_easy_private *privatep = luaL_checkudata(L, 1, LUACURL_EASYMETATABLE); CURL *curl = privatep->curl; CURLoption *optionp = LUACURL_OPTIONP_UPVALUE(L, 1); long value = luaL_checklong(L,2); if (curl_easy_setopt(curl, *optionp, value) != CURLE_OK) luaL_error(L, "%s", privatep->error); return 0; }
static int str_sub (lua_State *L) { size_t l; const lua_WChar *s = luaL_checklwstring(L, 1, &l); sint32 start = posrelat(luaL_checklong(L, 2), l); sint32 end = posrelat(luaL_optlong(L, 3, -1), l); if (start < 1) start = 1; if (end > (sint32)l) end = l; if (start <= end) lua_pushlwstring(L, s+start-1, end-start+1); else lua_pushwliteral(L, L""); return 1; }
/* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ tb_int_t xm_os_sleep(lua_State* lua) { // check tb_assert_and_check_return_val(lua, 0); // get the interval (ms) tb_long_t interval = (tb_long_t)luaL_checklong(lua, 1); // sleep it if (interval >= 0) tb_msleep(interval); // ok return 0; }
/** * @brief Removes an NPC. * * @usage misn.npcRm( npc_id ) * * @luaparam id ID of the NPC to remove. * @luafunc npcRm( id ) */ static int misn_npcRm( lua_State *L ) { unsigned int id; int ret; Mission *cur_mission; id = luaL_checklong(L, 1); cur_mission = misn_getFromLua(L); ret = npc_rm_mission( id, cur_mission ); if (ret != 0) NLUA_ERROR(L, "Invalid NPC ID!"); return 0; }
static void torch_(Tensor_c_readTensorStorageSize)(lua_State *L, int index, int allowNone, int allowTensor, int allowStorage, THStorage **storage_, long *storageOffset_, THLongStorage **size_) { static char errMsg[64]; THTensor *src = NULL; THStorage *storage = NULL; int arg1Type = lua_type(L, index); if( allowNone && (arg1Type == LUA_TNONE) ) { *storage_ = NULL; *storageOffset_ = 0; *size_ = THLongStorage_new(); return; } else if( allowTensor && (arg1Type == LUA_TUSERDATA) && (src = luaT_toudata(L, index, torch_(Tensor_id))) ) { *storage_ = THTensor_(storage)(src); *storageOffset_ = THTensor_(storageOffset)(src); *size_ = THTensor_(newSizeOf)(src); return; } else if( allowStorage && (arg1Type == LUA_TUSERDATA) && (storage = luaT_toudata(L, index, torch_(Storage_id))) ) { *storage_ = storage; if(lua_isnone(L, index+1)) { *storageOffset_ = 0; *size_ = THLongStorage_newWithSize(1); THLongStorage_set(*size_, 1, THStorage_(size)(storage)); } else { *storageOffset_ = luaL_checklong(L, index+1)-1; torch_(Tensor_c_readSize)(L, index+2, size_); } return; } else if( (arg1Type == LUA_TNUMBER) || (luaT_toudata(L, index, torch_LongStorage_id)) ) { *storage_ = NULL; *storageOffset_ = 0; torch_(Tensor_c_readSize)(L, index, size_); return; } sprintf(errMsg, "expecting number%s%s", (allowTensor ? " or Tensor" : ""), (allowStorage ? " or Storage" : "")); luaL_argcheck(L, 0, index, errMsg); }
static int sequence_region_lua_new(lua_State *L) { GtGenomeNode **rn; GtUword startpos, endpos; const char *seqid; GtStr *seqid_str; gt_assert(L); /* get_check parameters */ seqid = luaL_checkstring(L, 1); startpos = luaL_checklong(L, 2); endpos = luaL_checklong(L, 3); luaL_argcheck(L, startpos > 0, 2, "must be > 0"); luaL_argcheck(L, endpos > 0, 3, "must be > 0"); luaL_argcheck(L, startpos <= endpos, 2, "must be <= endpos"); /* construct object */ rn = lua_newuserdata(L, sizeof (GtGenomeNode*)); seqid_str = gt_str_new_cstr(seqid); *rn = gt_region_node_new(seqid_str, startpos, endpos); gt_str_delete(seqid_str); gt_assert(*rn); luaL_getmetatable(L, GENOME_NODE_METATABLE); lua_setmetatable(L, -2); return 1; }
/** * @brief Removes an NPC. * * @usage evt.npcRm( npc_id ) * * @luaparam id ID of the NPC to remove. * @luafunc npcRm( id ) */ static int evt_npcRm( lua_State *L ) { unsigned int id; int ret; Event_t *cur_event; id = luaL_checklong(L, 1); cur_event = event_getFromLua(L); ret = npc_rm_event( id, cur_event->id ); if (ret != 0) NLUA_ERROR(L, "Invalid NPC ID!"); return 0; }
void lsqlite3lib_xfinal_callback(sqlite3_context* ctx) { func* f = (func*)sqlite3_user_data(ctx); conn* c = f->c; int* ref = sqlite3_aggregate_context(ctx, sizeof(int)); if(!ref) sqlite3_result_error_nomem(ctx); lua_rawgeti(c->L, LUA_REGISTRYINDEX, c->ref); lua_rawgeti(c->L, -1, IDX_FUNCTION_TABLE); lua_pushstring(c->L, f->func_name); lua_rawget(c->L, -2); lua_rawgeti(c->L, -1, IDX_FUNC_XFINAL); lua_rawgeti(c->L, LUA_REGISTRYINDEX, *ref); lua_call(c->L, 1, 1); if(*ref != 0) { luaL_unref(c->L, LUA_REGISTRYINDEX, *ref); *ref = 0; } switch(lua_type(c->L, -1)) { case LUA_TBOOLEAN: sqlite3_result_int(ctx, lua_tointeger(c->L, -1)); break; case LUA_TNUMBER: if(luaL_checknumber(c->L, -1) - luaL_checklong(c->L, -1) > 0) { sqlite3_result_double(ctx, lua_tonumber(c->L, -1)); } else { sqlite3_result_int(ctx, lua_tointeger(c->L, -1)); } break; case LUA_TSTRING: { const char* ret = lua_tostring(c->L, -1); sqlite3_result_text(ctx, ret, strlen(ret), SQLITE_TRANSIENT); break; } case LUA_TNIL: default: sqlite3_result_null(ctx); break; } lua_pop(c->L, 2); }
int l_createMesh(lua_State *L) { vector<ofPoint> verts; vector<ofIndexType> indices; vector<ofPoint> normals; // vertices int vertNum = lua_objlen(L, 1); for(int i=0;i<vertNum;i+=3) { lua_rawgeti(L, 1, i+1); double x = luaL_checknumber(L, -1); lua_pop(L,1); lua_rawgeti(L, 1, i+2); double y = luaL_checknumber(L, -1); lua_pop(L,1); lua_rawgeti(L, 1, i+3); double z = luaL_checknumber(L, -1); lua_pop(L,1); verts.push_back(ofPoint(x,y,z)); } // indices int indNum = lua_objlen(L, 2); for(int i=1;i<=indNum;i++) { lua_rawgeti(L, 2, i); indices.push_back(luaL_checklong(L, -1)); lua_pop(L, 1); } // normals int normNum = lua_objlen(L, 3); for(int i=0;i<normNum;i+=3) { lua_rawgeti(L, 3, i+1); double x = luaL_checknumber(L, -1); lua_pop(L, 1); lua_rawgeti(L, 3, i+2); double y = luaL_checknumber(L, -1); lua_pop(L, 1); lua_rawgeti(L, 3, i+3); double z = luaL_checknumber(L, -1); lua_pop(L, 1); normals.push_back(ofPoint(x,y,z)); } lua_pop(L, 1); ofMesh **a = (ofMesh **)lua_newuserdata(L, sizeof(ofMesh *)); *a = createMesh(verts, indices, normals).get(); luaL_getmetatable(L, "app.mesh"); lua_setmetatable(L, -2); return 1; }
static int lcurl_opt_set_long_(lua_State *L, int opt){ lcurl_share_t *p = lcurl_getshare(L); long val; CURLSHcode code; if(lua_isboolean(L, 2)) val = lua_toboolean(L, 2); else{ luaL_argcheck(L, lua_type(L, 2) == LUA_TNUMBER, 2, "number or boolean expected"); val = luaL_checklong(L, 2); } code = curl_share_setopt(p->curl, opt, val); if(code != CURLSHE_OK){ return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_SHARE, code); } lua_settop(L, 1); return 1; }
static int torch_DiskFile_seek(lua_State *L) { DiskFile *file = luaT_checkudata(L, 1, torch_DiskFile_id); long position = luaL_checklong(L, 2)-1; luaL_argcheck(L, file->handle, 1, "attempt to use a closed file"); luaL_argcheck(L, position >= 0, 2, "position must be positive"); if(fseek(file->handle, position, SEEK_SET) < 0) { file->flags.hasError = 1; if(!file->flags.isQuiet) luaL_error(L, "unable to seek at position %d", position); } lua_settop(L, 1); return 1; }
static int torch_(Tensor___newindex__)(lua_State *L) { if(lua_isnumber(L, 2)) { THTensor *tensor = luaT_checkudata(L, 1, torch_(Tensor_id)); long index = luaL_checklong(L,2)-1; real value = (real)luaL_checknumber(L,3); luaL_argcheck(L, THTensor_(nDimension)(tensor) == 1, 1, "must be a one dimensional tensor"); THTensor_(set1d)(tensor, index, value); lua_pushboolean(L, 1); } else lua_pushboolean(L, 0); return 1; }
static int lua_TransformListener_transformChanged(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 3: { if ((lua_type(state, 1) == LUA_TUSERDATA) && (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) && lua_type(state, 3) == LUA_TNUMBER) { // Get parameter 1 off the stack. bool param1Valid; gameplay::ScriptUtil::LuaArray<Transform> param1 = gameplay::ScriptUtil::getObjectPointer<Transform>(2, "Transform", false, ¶m1Valid); if (!param1Valid) { lua_pushstring(state, "Failed to convert parameter 1 to type 'Transform'."); lua_error(state); } // Get parameter 2 off the stack. long param2 = (long)luaL_checklong(state, 3); Transform::Listener* instance = getInstance(state); instance->transformChanged(param1, param2); return 0; } lua_pushstring(state, "lua_TransformListener_transformChanged - Failed to match the given parameters to a valid function signature."); lua_error(state); break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 3)."); lua_error(state); break; } } return 0; }
static int eja_ioctl(lua_State *L) { size_t len; int ret; FILE *f = *(FILE**) luaL_checkudata(L, 1, LUA_FILEHANDLE); unsigned long request=luaL_checklong(L,2); const char *argp=luaL_checklstring(L, 3, &len); int fd=fileno(f); if (fd > 0) { ret=ioctl(fd, request, argp); lua_pushlstring(L, argp, len); lua_pushinteger(L, ret); } else { lua_pushnil(L); } return 1; }
static int csa_stream_lua_new(lua_State *L) { GtNodeStream **csa_stream, **in_stream; long join_length; in_stream = check_genome_stream(L, 1); if (lua_gettop(L) >= 2) { join_length = luaL_checklong(L, 2); luaL_argcheck(L, join_length >= 0, 2, "must be >= 0"); } else join_length = GT_DEFAULT_JOIN_LENGTH; csa_stream = lua_newuserdata(L, sizeof (GtNodeStream*)); gt_assert(csa_stream); *csa_stream = gt_csa_stream_new(*in_stream, join_length); luaL_getmetatable(L, GENOME_STREAM_METATABLE); lua_setmetatable(L, -2); return 1; }
/** * @brief Removes a hook previously created. * * @usage hook.rm( h ) -- Hook is removed * * @luaparam h Identifier of the hook to remove. * @luafunc rm( h ) */ static int hookL_rm( lua_State *L ) { unsigned int h; /* Remove the hook. */ h = luaL_checklong( L, 1 ); hook_rm( h ); /* Clean up hook data. */ lua_getglobal( L, "__hook_arg" ); if (!lua_isnil(L,-1)) { lua_pushnumber( L, h ); /* t, n */ lua_pushnil( L ); /* t, n, nil */ lua_settable( L, -3 ); /* t */ } lua_pop( L, 1 ); /* */ return 0; }
/** * @brief Jettisons the mission cargo. * * @luaparam cargoid ID of the cargo to jettison. * @luareturn true on success. * @luafunc jetCargo( cargoid ) */ static int misn_jetCargo( lua_State *L ) { int ret; unsigned int id; id = luaL_checklong(L,1); /* First try to remove the cargo from player. */ if (pilot_rmMissionCargo( player, id, 1 ) != 0) { lua_pushboolean(L,0); return 1; } /* Now unlink the mission cargo if it was successful. */ ret = mission_unlinkCargo( cur_mission, id ); lua_pushboolean(L,!ret); return 1; }
int lua_PhysicsGhostObject_transformChanged(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 3: { if ((lua_type(state, 1) == LUA_TUSERDATA) && (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) && lua_type(state, 3) == LUA_TNUMBER) { // Get parameter 1 off the stack. Transform* param1 = ScriptUtil::getObjectPointer<Transform>(2, "Transform", false); // Get parameter 2 off the stack. long param2 = (long)luaL_checklong(state, 3); PhysicsGhostObject* instance = getInstance(state); instance->transformChanged(param1, param2); return 0; } else { lua_pushstring(state, "lua_PhysicsGhostObject_transformChanged - Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 3)."); lua_error(state); break; } } return 0; }
int lua_AIMessage_setLong(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 3: { if ((lua_type(state, 1) == LUA_TUSERDATA) && lua_type(state, 2) == LUA_TNUMBER && lua_type(state, 3) == LUA_TNUMBER) { // Get parameter 1 off the stack. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2); // Get parameter 2 off the stack. long param2 = (long)luaL_checklong(state, 3); AIMessage* instance = getInstance(state); instance->setLong(param1, param2); return 0; } else { lua_pushstring(state, "lua_AIMessage_setLong - Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 3)."); lua_error(state); break; } } return 0; }
/** * @brief Changes an overlay message. * * @usage player.omsgChange( omsg_id, "new message", 3 ) * @luaparam id ID of the overlay message to change. * @luaparam msg Message to change to. * @luaparam duration New duration to set (0. for infinity). * @luareturn true if all went well, false otherwise. * @luafunc omsgChange( id, msg, duration ) */ static int playerL_omsgChange( lua_State *L ) { const char *str; double duration; unsigned int id; int ret; /* Input. */ id = luaL_checklong(L,1); str = luaL_checkstring(L,2); duration = luaL_checknumber(L,3); /* Infinity. */ if (duration < 1e-10) duration = INFINITY; /* Output. */ ret = omsg_change( id, str, duration ); lua_pushboolean(L,!ret); return 1; }
int libkv_getvalue(lua_State *L) { if(2 != lua_gettop(L)){ lua_pushboolean( L, 0 ); lua_pushstring(L, "[libkv_getvalue]parameter must input command , len of command"); return 2; } const char *command = luaL_checkstring(L, 1); long len = luaL_checklong(L,2); if(NULL == command || 0 == len){ lua_pushboolean( L, 0 ); lua_pushstring(L, "[libkv__getvalue] command or len of command is error"); return 2; } answer_t*ans = NULL; ans = kv_ask(command, len); if(ERR_NONE != ans->errnum){ lua_pushboolean(L,0); lua_pushstring(L,ans->err); answer_release(ans); return 2; } answer_value_t* value = NULL; value = answer_first_value(ans); if(NULL != value){ lua_pushboolean(L,1); lua_pushstring(L,answer_value_to_string(value)); answer_release(ans); return 2; } answer_release(ans); lua_pushboolean( L, 0 ); lua_pushstring(L, "[libkv_getvalue] get failed"); return 2; }
static int lcurl_share_setopt(lua_State *L){ lcurl_share_t *p = lcurl_getshare(L); int opt; luaL_checkany(L, 2); if(lua_type(L, 2) == LUA_TTABLE){ int ret = lcurl_utils_apply_options(L, 2, 1, 0, p->err_mode, LCURL_ERROR_SHARE, CURLSHE_BAD_OPTION); if(ret) return ret; lua_settop(L, 1); return 1; } opt = luaL_checklong(L, 2); lua_remove(L, 2); #define OPT_ENTRY(l, N, T, S) case CURLSHOPT_##N: return lcurl_share_set_##N(L); switch(opt){ #include "lcoptshare.h" } #undef OPT_ENTRY return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_SHARE, CURLSHE_BAD_OPTION); }
LUA_API int l_xev_queue_poll(lua_State* L){ struct xev_queue *queue=lua_touserdata(L, 1); long timeout=luaL_checklong(L, 2); lua_pushinteger(L, xev_queue_poll(queue,timeout)); return 1; }
long LuaState::CheckLong(int numArg) { return (long)luaL_checklong(m_state, numArg); }
template<> int32 Eluna::CHECKVAL<int32>(lua_State* L, int narg) { return luaL_checklong(L, narg); }
int L_htonl(lua_State *L) { uint32_t n = (uint32_t)luaL_checklong(L, 1); n = htonl(n); lua_pushlstring(L, (const char*)&n, 4); return 1; }
long to(lua_State * L, int index, return_tag<long>) { return static_cast<long>(luaL_checklong(L, index)); }