static int lua_mmio_read(lua_State *L) { mmio_t *mmio; uint8_t *buf; uintptr_t offset; unsigned int i, len; int ret; mmio = luaL_checkudata(L, 1, "periphery.MMIO"); lua_mmio_checktype(L, 2, LUA_TNUMBER); lua_mmio_checktype(L, 3, LUA_TNUMBER); offset = lua_tounsigned(L, 2); len = lua_tounsigned(L, 3); if ((buf = malloc(len)) == NULL) return lua_mmio_error(L, MMIO_ERROR_ALLOC, errno, "Error: allocating memory"); if ((ret = mmio_read(mmio, offset, buf, len)) < 0) { free(buf); return lua_mmio_error(L, ret, mmio_errno(mmio), "Error: %s", mmio_errmsg(mmio)); } /* Convert byte buffer to byte table */ lua_newtable(L); for (i = 0; i < len; i++) { lua_pushunsigned(L, i+1); lua_pushunsigned(L, buf[i]); lua_settable(L, -3); } free(buf); return 1; }
int lua_Drawable_draw(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 1: { if ((lua_type(state, 1) == LUA_TUSERDATA)) { Drawable* instance = getInstance(state); unsigned int result = instance->draw(); // Push the return value onto the stack. lua_pushunsigned(state, result); return 1; } lua_pushstring(state, "lua_Drawable_draw - Failed to match the given parameters to a valid function signature."); lua_error(state); break; } case 2: { if ((lua_type(state, 1) == LUA_TUSERDATA) && lua_type(state, 2) == LUA_TBOOLEAN) { // Get parameter 1 off the stack. bool param1 = gameplay::ScriptUtil::luaCheckBool(state, 2); Drawable* instance = getInstance(state); unsigned int result = instance->draw(param1); // Push the return value onto the stack. lua_pushunsigned(state, result); return 1; } lua_pushstring(state, "lua_Drawable_draw - Failed to match the given parameters to a valid function signature."); lua_error(state); break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1 or 2)."); lua_error(state); break; } } return 0; }
static int lua_likwid_getCpuInfo(lua_State* L) { if (topology_isInitialized == 0) { topology_init(); topology_isInitialized = 1; cpuinfo = get_cpuInfo(); } if ((topology_isInitialized) && (cpuinfo == NULL)) { cpuinfo = get_cpuInfo(); } lua_newtable(L); lua_pushstring(L,"family"); lua_pushunsigned(L,cpuinfo->family); lua_settable(L,-3); lua_pushstring(L,"model"); lua_pushunsigned(L,cpuinfo->model); lua_settable(L,-3); lua_pushstring(L,"stepping"); lua_pushunsigned(L,cpuinfo->stepping); lua_settable(L,-3); lua_pushstring(L,"clock"); lua_pushunsigned(L,cpuinfo->clock); lua_settable(L,-3); lua_pushstring(L,"turbo"); lua_pushinteger(L,cpuinfo->turbo); lua_settable(L,-3); lua_pushstring(L,"name"); lua_pushstring(L,cpuinfo->name); lua_settable(L,-3); lua_pushstring(L,"osname"); lua_pushstring(L,cpuinfo->osname); lua_settable(L,-3); lua_pushstring(L,"short_name"); lua_pushstring(L,cpuinfo->short_name); lua_settable(L,-3); lua_pushstring(L,"features"); lua_pushstring(L,cpuinfo->features); lua_settable(L,-3); lua_pushstring(L,"isIntel"); lua_pushinteger(L,cpuinfo->isIntel); lua_settable(L,-3); lua_pushstring(L,"featureFlags"); lua_pushunsigned(L,cpuinfo->featureFlags); lua_settable(L,-3); lua_pushstring(L,"perf_version"); lua_pushunsigned(L, cpuinfo->perf_version); lua_settable(L,-3); lua_pushstring(L,"perf_num_ctr"); lua_pushunsigned(L,cpuinfo->perf_num_ctr); lua_settable(L,-3); lua_pushstring(L,"perf_width_ctr"); lua_pushunsigned(L,cpuinfo->perf_width_ctr); lua_settable(L,-3); lua_pushstring(L,"perf_num_fixed_ctr"); lua_pushunsigned(L,cpuinfo->perf_num_fixed_ctr); lua_settable(L,-3); return 1; }
void luaH_pushnmeadate(lua_State * lua, const struct nmea_date_t * t) { lua_newtable(lua); lua_pushunsigned(lua, t->y); lua_setfield(lua, -2, "y"); lua_pushunsigned(lua, t->m); lua_setfield(lua, -2, "m"); lua_pushunsigned(lua, t->d); lua_setfield(lua, -2, "d"); }
static int lgetcolor(lua_State *L) { struct sprite *s = self(L); if (s->type != TYPE_LABEL) { lua_pushunsigned(L, s->t.color); } else { lua_pushunsigned(L, label_get_color(s->s.label, &s->t)); } return 1; }
void luaH_pushnmeatime(lua_State * lua, const struct nmea_time_t * t) { lua_newtable(lua); lua_pushunsigned(lua, t->h); lua_setfield(lua, -2, "h"); lua_pushunsigned(lua, t->m); lua_setfield(lua, -2, "m"); lua_pushunsigned(lua, t->s); lua_setfield(lua, -2, "s"); lua_pushunsigned(lua, t->ms); lua_setfield(lua, -2, "ms"); }
static int pushdecval(struct lua_State *L, struct rnn *rnn, uint32_t regval, struct rnntypeinfo *info) { union rnndecval val; switch (rnn_decodelem(rnn, info, regval, &val)) { case RNN_TTYPE_INT: case RNN_TTYPE_ENUM: case RNN_TTYPE_INLINE_ENUM: lua_pushinteger(L, val.i); return 1; case RNN_TTYPE_UINT: case RNN_TTYPE_HEX: lua_pushunsigned(L, val.u); return 1; case RNN_TTYPE_FLOAT: lua_pushnumber(L, val.f); return 1; case RNN_TTYPE_BOOLEAN: lua_pushboolean(L, val.u); return 1; case RNN_TTYPE_INVALID: default: return 0; } }
static int lua_FontGlyph_advance(lua_State* state) { // Validate the number of parameters. if (lua_gettop(state) > 2) { lua_pushstring(state, "Invalid number of parameters (expected 1 or 2)."); lua_error(state); } Font::Glyph* instance = getInstance(state); if (lua_gettop(state) == 2) { // Get parameter 2 off the stack. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2); instance->advance = param2; return 0; } else { unsigned int result = instance->advance; // Push the return value onto the stack. lua_pushunsigned(state, result); return 1; } }
int name_value_collection___index(lua_State *L) { NameValueCollection *collection = GetCollection(L, 1); const char *name = luaL_checkstring(L, 2); if (strcmp(name, "Count") == 0) { lua_pushunsigned(L, collection->GetCount()); } else if (strcmp(name, "AllKeys") == 0) { StringVectorToLuaArray(L, collection->AllKeys()); } else if (strcmp(name, "Add") == 0) { lua_pushlightuserdata(L, (void *)collection); lua_pushcclosure(L, name_value_collection_Add, 1); } else if (strcmp(name, "Get") == 0) { lua_pushlightuserdata(L, (void *)collection); lua_pushcclosure(L, name_value_collection_Get, 1); } else if (strcmp(name, "GetKey") == 0) { lua_pushlightuserdata(L, (void *)collection); lua_pushcclosure(L, name_value_collection_GetKey, 1); } else if (strcmp(name, "GetValues") == 0) { lua_pushlightuserdata(L, (void *)collection); lua_pushcclosure(L, name_value_collection_GetValues, 1); } else if (strcmp(name, "Clear") == 0) { lua_pushlightuserdata(L, (void *)collection); lua_pushcclosure(L, name_value_collection_Clear, 1); } else if (strcmp(name, "Set") == 0) { lua_pushlightuserdata(L, (void *)collection); lua_pushcclosure(L, name_value_collection_Set, 1); } else if (strcmp(name, "Remove") == 0) { lua_pushlightuserdata(L, (void *)collection); lua_pushcclosure(L, name_value_collection_Remove, 1); } else { lua_pushstring(L, "Unknown property or method."); lua_error(L); } return 1; }
static void PushReg(lua_State * L, RegUser * r) { lua_checkstack(L, 3); // we need 3 (1 table, 2 id, 3 value) empty slots in stack, check it to be sure lua_newtable(L); int i = lua_gettop(L); lua_pushliteral(L, "sNick"); lua_pushstring(L, r->sNick); lua_rawset(L, i); lua_pushliteral(L, "sPassword"); if(r->bPassHash == true) { lua_pushnil(L); } else { lua_pushstring(L, r->sPass); } lua_rawset(L, i); lua_pushliteral(L, "iProfile"); #if LUA_VERSION_NUM < 503 lua_pushnumber(L, r->ui16Profile); #else lua_pushunsigned(L, r->ui16Profile); #endif lua_rawset(L, i); }
static int GetRegs(lua_State * L) { if(lua_gettop(L) != 0) { luaL_error(L, "bad argument count to 'GetRegs' (0 expected, got %d)", lua_gettop(L)); lua_settop(L, 0); lua_pushnil(L); return 1; } lua_newtable(L); int t = lua_gettop(L), i = 0; RegUser *next = clsRegManager::mPtr->RegListS; while(next != NULL) { RegUser *curReg = next; next = curReg->next; #if LUA_VERSION_NUM < 503 lua_pushnumber(L, ++i); #else lua_pushunsigned(L, ++i); #endif PushReg(L, curReg); lua_rawset(L, t); } return 1; }
static int ltotal(lua_State *L) { size_t t = malloc_used_memory(); lua_pushunsigned(L, t); return 1; }
int lua_Curve_getRefCount(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 1: { if ((lua_type(state, 1) == LUA_TUSERDATA)) { Curve* instance = getInstance(state); unsigned int result = instance->getRefCount(); // Push the return value onto the stack. lua_pushunsigned(state, result); return 1; } lua_pushstring(state, "lua_Curve_getRefCount - Failed to match the given parameters to a valid function signature."); lua_error(state); break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; }
static int test_unsigned (lua_State *L) { lua_Unsigned u = luaL_checkunsigned(L, 1); lua_Unsigned u2 = lua_tounsigned(L, 1); lua_pushunsigned(L, u); lua_pushboolean(L, u == u2); return 2; }
int _lua_rabbit_mouse_fetch_cursor(lua_State * L) { int argc = lua_gettop(L); unsigned int ret_0; rabbit_mouse_fetch_cursor(&ret_0); lua_pushunsigned(L, ret_0); return 1; }
static void io_list_to_lua_stack(void **list, lua_State *L) { gds_iterator_t *(*iterator_callback)(void *); emb_type_t *type; type = emb_type(list); iterator_callback = emb_type_get_callback(type, "gds_iterator"); if (iterator_callback) { gds_iterator_t *it; void **val; unsigned int i = 1; lua_newtable(L); it = iterator_callback(*list); while (!gds_iterator_step(it)) { val = gds_iterator_get(it); lua_pushunsigned(L, i); io_object_to_lua_stack(val, L); lua_settable(L, -3); i++; } gds_iterator_free(it); } else { lua_pushnil(L); } }
static int lread(lua_State *L) { struct boxreader * box = lua_touserdata(L, 1); luaL_checktype(L, 2, LUA_TFUNCTION); struct stm_copy * copy = stm_copy(box->obj); if (copy == box->lastcopy) { // not update stm_releasecopy(copy); lua_pushboolean(L, 0); return 1; } stm_releasecopy(box->lastcopy); box->lastcopy = copy; if (copy) { lua_settop(L, 2); lua_pushlightuserdata(L, copy->msg); lua_pushunsigned(L, copy->sz); lua_call(L, 2, LUA_MULTRET); lua_pushboolean(L, 1); lua_replace(L, 1); return lua_gettop(L); } else { lua_pushboolean(L, 0); return 1; } }
static int GetRegsByOpStatus(lua_State * L, const bool &bOperator) { if(lua_gettop(L) != 0) { if(bOperator == true) { luaL_error(L, "bad argument count to 'GetOps' (0 expected, got %d)", lua_gettop(L)); } else { luaL_error(L, "bad argument count to 'GetNonOps' (0 expected, got %d)", lua_gettop(L)); } lua_settop(L, 0); lua_pushnil(L); return 1; } lua_newtable(L); int t = lua_gettop(L), i = 0; RegUser *next = clsRegManager::mPtr->RegListS; while(next != NULL) { RegUser *curReg = next; next = curReg->next; if(clsProfileManager::mPtr->IsProfileAllowed(curReg->ui16Profile, clsProfileManager::HASKEYICON) == bOperator) { #if LUA_VERSION_NUM < 503 lua_pushnumber(L, ++i); #else lua_pushunsigned(L, ++i); #endif PushReg(L, curReg); lua_rawset(L, t); } } return 1; }
static int lblock(lua_State *L) { size_t t = malloc_memory_block(); lua_pushunsigned(L, t); return 1; }
/** * Fills the table within the Lua state with the NMEA data. * Supported NMEA sentences are: * - RMC */ void luaH_msg_to_table_nmea(lua_State * lua, const struct message_t * msg) { struct msg_nmea_t { uint32_t type; void (*func)(lua_State *, const struct nmea_t *); }; static const struct msg_nmea_t CONV[] = { { NMEA_RMC, msg_to_table_nmea_rmc }, }; const struct nmea_t * nmea = &msg->data.attr.nmea; size_t i; lua_newtable(lua); lua_pushunsigned(lua, nmea->type); lua_setfield(lua, -2, "nmea_type"); lua_pushstring(lua, nmea->raw); lua_setfield(lua, -2, "raw"); lua_newtable(lua); for (i = 0; i < sizeof(CONV) / sizeof(CONV[0]); ++i) { if ((CONV[i].type == nmea->type) && CONV[i].func) { CONV[i].func(lua, nmea); break; } } lua_setfield(lua, -2, "sentence"); lua_setfield(lua, -2, "nmea"); }
static int b_xor (lua_State *L) { int i, n = lua_gettop(L); lua_Unsigned r = 0; for (i = 1; i <= n; i++) r ^= luaL_checkunsigned(L, i); lua_pushunsigned(L, trim(r)); return 1; }
static int GetScripts(lua_State * L) { if(lua_gettop(L) != 0) { luaL_error(L, "bad argument count to 'GetScripts' (0 expected, got %d)", lua_gettop(L)); lua_settop(L, 0); lua_pushnil(L); return 1; } lua_newtable(L); int t = lua_gettop(L), n = 0; for(uint8_t ui8i = 0; ui8i < clsScriptManager::mPtr->ui8ScriptCount; ui8i++) { #if LUA_VERSION_NUM < 503 lua_pushnumber(L, ++n); #else lua_pushunsigned(L, ++n); #endif lua_newtable(L); int s = lua_gettop(L); lua_pushliteral(L, "sName"); lua_pushstring(L, clsScriptManager::mPtr->ScriptTable[ui8i]->sName); lua_rawset(L, s); lua_pushliteral(L, "bEnabled"); clsScriptManager::mPtr->ScriptTable[ui8i]->bEnabled == true ? lua_pushboolean(L, 1) : lua_pushnil(L); lua_rawset(L, s); lua_pushliteral(L, "iMemUsage"); clsScriptManager::mPtr->ScriptTable[ui8i]->LUA == NULL ? lua_pushnil(L) : #if LUA_VERSION_NUM < 503 lua_pushnumber(L, lua_gc(clsScriptManager::mPtr->ScriptTable[ui8i]->LUA, LUA_GCCOUNT, 0)); #else lua_pushunsigned(L, lua_gc(clsScriptManager::mPtr->ScriptTable[ui8i]->LUA, LUA_GCCOUNT, 0)); #endif lua_rawset(L, s); lua_rawset(L, t); } return 1; }
int getObjectById(lua_State *l) { Ogre::String sID(lua_tostring(l, 1)); CPhysicsUserPointer *pObject = GameScriptParser::getSingleton().getMap()->getObjectManager().getObjectBySafeStateId(sID); unsigned int id = GameScriptParser::getSingleton().getIDOfPointerOrAdd(pObject, GameScriptParser::UserPointerData::PHYSICS_USER_POINTER); lua_pushunsigned(l,id); return 1; }
int my_lua_readn(lua_State *state) { hw_readn_fn_t fn = (hw_readn_fn_t)lua_touserdata(state, lua_upvalueindex(1)); int n = lua_gettop(state); if(n != 1) luaL_error(state, "readn takes a single argument"); lua_pushunsigned(state, fn(state, luaL_checkunsigned(state, 1))); return 1; }
int my_lua_read_reg(lua_State *state) { int n = lua_gettop(state); if(n != 0) luaL_error(state, "read() takes no argument"); soc_addr_t addr = lua_tounsigned(state, lua_upvalueindex(1)); lua_pushunsigned(state, hw_read32(state, addr)); return 1; }
static int lua_spi_transfer(lua_State *L) { spi_t *spi; uint8_t *buf; unsigned int i, len; int ret; spi = luaL_checkudata(L, 1, "periphery.SPI"); lua_spi_checktype(L, 2, LUA_TTABLE); len = luaL_len(L, 2); if ((buf = malloc(len)) == NULL) return lua_spi_error(L, SPI_ERROR_ALLOC, errno, "Error: allocating memory"); /* Convert byte table to byte buffer */ for (i = 0; i < len; i++) { lua_pushunsigned(L, i+1); lua_gettable(L, -2); if (!lua_isnumber(L, -1)) { free(buf); return lua_spi_error(L, SPI_ERROR_ARG, 0, "Error: invalid element index %d in bytes table.", i+1); } buf[i] = lua_tounsigned(L, -1); lua_pop(L, 1); } if ((ret = spi_transfer(spi, buf, buf, len)) < 0) { free(buf); return lua_spi_error(L, ret, spi_errno(spi), "Error: %s", spi_errmsg(spi)); } /* Convert byte buffer back to bytes table */ for (i = 0; i < len; i++) { lua_pushunsigned(L, i+1); lua_pushunsigned(L, buf[i]); lua_settable(L, -3); } free(buf); return 1; }
int jarray_create(lua_State* L, uintptr_t value) { lua_newtable(L); luaL_getmetatable(L, LUA_JASS_ARRAY); lua_setmetatable(L, -2); lua_pushstring(L, "__value"); lua_pushunsigned(L, value); lua_rawset(L, -3); return 1; }
void lsqlite3lib_profile_callback(void* p,const char* sql,sqlite3_uint64 time) { conn* c = (conn*)p; lua_rawgeti(c->L, LUA_REGISTRYINDEX, c->ref); lua_rawgeti(c->L, -1, IDX_CALLBACK_TABLE); lua_pushinteger(c->L, IDX_FUNC_PROFILE_CALLBACK); lua_rawget(c->L, -2); /* fnction */ lua_pushstring(c->L, sql); /* arg1 */ lua_pushunsigned(c->L, time); /* arg2 */ lua_call(c->L, 2, 0); lua_pop(c->L, 2); }
static int ianimation_name(lua_State* L) { int ret = 1; uint32_t name = 0; IAnimation* anim = ianimation_check(L, 1); if (anim != NULL) name = anim->name; lua_pushunsigned(L, name); return ret; }
void io_object_to_lua_stack(void **object, lua_State *L) { if (object == NULL) { lua_pushnil(L); return; } io_lua_value_t lua_value; lua_value.type = LUA_VALUE_TYPE_NONE; io_emb_data_to_lua_value(object, &lua_value); if (lua_value.type != LUA_VALUE_TYPE_NONE) { switch (lua_value.type) { case LUA_VALUE_TYPE_NIL: lua_pushnil(L); break; case LUA_VALUE_TYPE_BOOLEAN: lua_pushboolean(L, lua_value.value.boolean); break; case LUA_VALUE_TYPE_INTEGER: lua_pushinteger(L, lua_value.value.integer); break; case LUA_VALUE_TYPE_UNSIGNED: lua_pushunsigned(L, lua_value.value.unsignd); break; case LUA_VALUE_TYPE_NUMBER: lua_pushnumber(L, lua_value.value.number); break; case LUA_VALUE_TYPE_STRING: lua_pushstring(L, lua_value.value.string); break; case LUA_VALUE_TYPE_CFUNCTION: lua_pushcfunction(L, lua_value.value.cfunction); break; case LUA_VALUE_TYPE_LIST: io_list_to_lua_stack(object, L); break; case LUA_VALUE_TYPE_TABLE: io_table_to_lua_stack(object, L); break; case LUA_VALUE_TYPE_LIGHTUSERDATA: lua_pushlightuserdata(L, lua_value.value.lightuserdata); break; default: lua_pushnil(L); } } else { fprintf(stderr, "Unknown type (%s) in %s\n", emb_type_name(object), __func__); lua_pushnil(L); } }