lua-table

Print value from a lua table if pattern matches

◇◆丶佛笑我妖孽 提交于 2020-01-04 14:21:24
问题 Okay, so I just recently got into lua and find myself stuck with the following: I have the function peripheral.getNames() (which is a custom function) it will return a table with the structure key,value, whereas key is always a number and starts from 1 and value will be what the function finds (it searches for devices connected to it) In my example it creates a table which looks like this 1 herp 2 derp 3 monitor_1 4 morederp I can print the values with the following local pgn = peripherals

how to represent nil in a table

╄→尐↘猪︶ㄣ 提交于 2020-01-03 18:34:20
问题 Let's suppose I want to store a list of element. Including some nil values. The position of the values is significant, and I need to represent the absence of a value in the list at a given position. Here is a problem: a = {1,2,3,nil,4} for k,v in ipairs(a) do print(k,v) end print(a[4]) print(a[5]) The for loop will only print elements 1,2 and 3. It stops at nil. The first print statement prints nil, but I'm not sure if it is actually stored in the table or not. (Who knows?) The second print

how to represent nil in a table

泪湿孤枕 提交于 2020-01-03 18:34:06
问题 Let's suppose I want to store a list of element. Including some nil values. The position of the values is significant, and I need to represent the absence of a value in the list at a given position. Here is a problem: a = {1,2,3,nil,4} for k,v in ipairs(a) do print(k,v) end print(a[4]) print(a[5]) The for loop will only print elements 1,2 and 3. It stops at nil. The first print statement prints nil, but I'm not sure if it is actually stored in the table or not. (Who knows?) The second print

I need a tool to parse Lua tables, preferrably in Ruby or Java

拈花ヽ惹草 提交于 2020-01-01 06:18:51
问题 I need a tool to parse Lua table expressions. If all else fails, I will eventually just code a small Lua module to convert tables to XML, but for the time being, I am interested in a Ruby library doing that, but failing that, I would accept tool in any language, provided I can look at its source. Here is an example snippet (it's a WoW addon output): CT_RaidTracker_RaidLog = { { ["PlayerInfos"] = { ["Nyim"] = { ["race"] = "Orc", ["guild"] = "Excubitores Noctae", ["sex"] = 2, ["class"] =

I need a tool to parse Lua tables, preferrably in Ruby or Java

≡放荡痞女 提交于 2020-01-01 06:18:28
问题 I need a tool to parse Lua table expressions. If all else fails, I will eventually just code a small Lua module to convert tables to XML, but for the time being, I am interested in a Ruby library doing that, but failing that, I would accept tool in any language, provided I can look at its source. Here is an example snippet (it's a WoW addon output): CT_RaidTracker_RaidLog = { { ["PlayerInfos"] = { ["Nyim"] = { ["race"] = "Orc", ["guild"] = "Excubitores Noctae", ["sex"] = 2, ["class"] =

Why length is different in Lua

不想你离开。 提交于 2019-12-31 01:55:32
问题 I'm learning Lua for corona sdk and I have these local type1 = {nil, "(", nil, "x" ,nil , ")" ; n=6} local type2 = {"(",nil, "x",nil, ")",nil ; n=6} print(#type1) --prints 6 print(#type2) --prints 3 why the second one is not 6 too?? 回答1: The # operator doesn't work on every table, it works only on a sequence, that is, the set of its positive numeric keys is equal to {1..n} for some integer n . In that case, n is its length. For instance, local t = {"hello", 42, true} is a sequence. But both

Lua : remove duplicate elements

人走茶凉 提交于 2019-12-30 18:29:16
问题 i am having a table in lua test = {1,2,4,2,3,4,2,3,4,"A", "B", "A"} I want to remove all duplicate elements in table. Output should be test = {1,2,4,3,"A","B"} EDIT: My try : > items = {1,2,4,2,3,4,2,3,4,"A", "B", "A"} > flags = {} > for i=1,table.getn(items) do if not flags[items[i]] then io.write(' ' .. items[i]) flags[items[i]] = true end >> end 1 2 4 3 A B> It is working fine now. Thanks for answers and comments. 回答1: Similar to example given by @Dimitry but only one loop local test = {1

Iterating over table of tables with the Lua C API

喜你入骨 提交于 2019-12-30 07:07:08
问题 I'm trying to iterate over a table of tables in Lua and output: The key of each table. The key / value pair of each entry in each table. Here is the code: void print_table(lua_State *L) { lua_pushnil(L); while(lua_next(L, -2) != 0) { const char *key = lua_tostring(L, -2); if(lua_isstring(L, -1)) printf("%s = %s", key, lua_tostring(L, -1)); else if(lua_isnumber(L, -1)) printf("%s = %d", key, lua_tonumber(L, -1)); else if(lua_istable(L, -1)) { printf("%s", key); PrintTable(L); } lua_pop(L, 1);

Images in an array, not spacing correctly

久未见 提交于 2019-12-25 10:00:49
问题 The shapes are at the top of the image. http://picturepush.com/public/6472916 The code looks like this: local xOffset = 0 for i = 1, levelPacks[prevCurrentLevelPack][prevCurrentLevel].ammount do if i == 1 then --setup first one shapesPrevArray[i].x = 30 shapesPrevArray[i].y = 41 shapesPrevArray[i].isVisible = true end if i > 1 then --setup the rest --width of previous one plus the x value of the previous one to make them next to eachother. xOffset = shapesPrevArray[i - 1].width +

Using a table in Lua to display text isn't working?

≡放荡痞女 提交于 2019-12-25 09:08:55
问题 I'm using Corona SDK, Sublime Text 3, and Lua. My goal in this particular program is to make a visual novel app that changes when the player clicks on the text displayed at the bottom of the screen to progress to the next text entry, therefore continuing the story. I set up a bunch of code for logo, title screen, and other things, that works perfectly. What I'm currently trying to do within the visual novel scene is to use a table to draw the text from by change the .TEXT property to select a