Lua,WOW和“......”(Lua, WOW and “…”)
让我的脚在Lua中湿透, 为魔兽世界编写一些简单的插件。 主要通过其他插件查看,检查代码等。我看到一件令我困惑的事情。 我知道
...
是一种将可变数量的参数传递给函数的方法,但我看到它在.lua
文件的开头使用:local parent, ns = ...
同样,这是源代码中的第一行。 我在文件中看到的唯一引用是在
.xml
文件中,作为脚本包含在内<Ui> <Script file="unitframes\options\ouf.lua"/> </Ui>
我很好奇传入的价值来自......
回答:
如下面的答案所示,WoW将参数传递给脚本。 显然,WoW将以下参数传递给脚本:
- AddOn的名称作为字符串(实际上是文件夹名称)
- AddOn独有的表(通常用作AddOn的命名空间)。 该表与插件中的所有lua文件共享,并提供“AddOn”唯一的作用域上下文。
Getting my feet wet in Lua and writing some simple addons for World of Warcraft. Primarily looking through other addons, inspecting the code, etc. I'm seeing one thing that has me confused. I know that
...
is a way to pass variable number of parameters to a function, but I'm seeing it used at the beginning of a.lua
file:local parent, ns = ...
Again, this is the first line in the source. The only references I see to the file is in the
.xml
file, included as a script<Ui> <Script file="unitframes\options\ouf.lua"/> </Ui>
I'm curious where the values being passed in are coming from...
ANSWER:
As the answer below indicates, WoW is passing the arguments to the script. Aparently, WoW passes the following arguments to a script:
- Name of the AddOn as a String (actually the folder name)
- A table unique to the AddOn (often used as the AddOn's namespace). This table is shared w/ all the lua files in the addon and provides an "AddOn" only scoped context.
原文:https://stackoverflow.com/questions/13565828
最满意答案
有几种不同的方法可以构建一行具有可变列数的输出。 哪一个最好可能取决于你在更大范围内实际做了什么。
一种简单的方法是循环遍历列值并对每个值进行
end
设置为换行符之外的其他值。 这将导致它在打印输出结束时跳过通常的换行符。 要在行尾添加换行符,您需要在print()
完所有列后进行常规print()
调用。另一种选择是为您的列构建一个单独的字符串,可能使用
str.join
。 根据你想要格式化的东西,这可能是" ".format(str(x) for x in years)
或者更复杂的东西。这是两个代码:
years = range(min_time, max_time + 1, increment_time) for year in years: print(year, end=" ") # prints a space after each value, rather than a newline print() # add a newline at the end of the row row_str = " ".join(str(year) for year in years) # join year strings with spaces print(row_str) # prints whole row in one step, with a newline at the end
There are a couple different ways that you can build a row of output with a variable number of columns. Which one will be best may depend on what you're actually doing on a larger scale.
One simple approach is to loop over your column values and make a
end
set to something other than a newline. This will cause it to skip the usual newline at the end of the printed output. To get a newline at the end of the row, you'll need to make a regularprint()
call after all the columns have been printed.Another option is to build a single string for your column, probably with
str.join
. Depending on how you want to format things, this might be" ".format(str(x) for x in years)
or maybe something more complicated.Here's code with both of those:
years = range(min_time, max_time + 1, increment_time) for year in years: print(year, end=" ") # prints a space after each value, rather than a newline print() # add a newline at the end of the row row_str = " ".join(str(year) for year in years) # join year strings with spaces print(row_str) # prints whole row in one step, with a newline at the end
相关问答
更多-
PHP循环X次数(PHP loop X amount of times)[2023-04-08]
for ($k = 0 ; $k < $columns; $k++){ echo ''; } for ($k = 0 ; $k < $columns; $k++){ echo ' '; } -
有几种不同的方法可以构建一行具有可变列数的输出。 哪一个最好可能取决于你在更大范围内实际做了什么。 一种简单的方法是循环遍历列值并对每个值进行print调用,并将关键字 - 仅参数end设置为换行符之外的其他值。 这将导致它在打印输出结束时跳过通常的换行符。 要在行尾添加换行符,您需要在print()完所有列后进行常规print()调用。 另一种选择是为您的列构建一个单独的字符串,可能使用str.join 。 根据你想要格式化的东西,这可能是" ".format(str(x) for x in years) ...
-
是的,您可以使用Array#fill方法。 array = [1,2,3,4,5] array.fill(12, array.size, 4) # => [1, 2, 3, 4, 5, 12, 12, 12, 12] 说明 假设你有一个数组a = [1,2,3] 。 现在a.size将给你3 ,其中最后一个索引是2 。 所以,当你在a.size使用#fill ,你会告诉你开始将对象从3推到n次。 Yes, You can using Array#fill method. array = [1,2,3,4, ...
-
它必须是'x'吗? 对于随机字符串,您可以在shell中使用它 $ dd if=/dev/urandom count=80 bs=1 Does it have to be 'x's? For a random string you can use this from the shell $ dd if=/dev/urandom count=80 bs=1
-
当然,使用:lt(5) 。 这意味着只选择前五个(0-4)个奇数元素。 例如: $('li:odd:lt(5)').css('background','red'); jsFiddle示例 请参阅: http : //api.jquery.com/lt-selector/ Sure, use :lt(5). This means only select the first five (0-4) odd elements. For example: $('li:odd:lt(5)').css('backgrou ...
-
如何使用python将列表索引值向前移动'x'次?(how can I move a list index value forward 'x' amount of times using python?)[2021-12-16]
尝试: >>> s = 'abc' >>> ''.join(chr(ord(c)+2) for c in s) 'cde' 以上不仅限于标准ASCII:它通过unicode字符集进行处理。 限制为26个字符 >>> s = 'abcyz' >>> ''.join(chr(ord('a')+(ord(c)-ord('a')+2) % 26) for c in s) 'cdeab' 修改原始代码 如果我们想要仅修改原始文件以使其正常工作: from string import ascii_lowercase ... -
您只需每次重新计算一个新的随机数。 for x in range(0, 3): sent = random.randrange(0,1100) print(Words[sent]) 虽然你的情况可能更容易使用内置的random.choices()函数: print(random.choices(Words, k=3)) 将从您的Words列表中打印3个随机Words列表。 如果你没有使用Python 3.6,那么你可以random.choice(Words)调用random.choice ...
-
添加两行,试一试: from random import * rankName = ("Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King") suit = ("hearts", "diamonds", "spades" , "clubs") users = ("I", "computer", "deck") # make it weighted a ...
-
你很近...... return str * 4 You are close... return str * 4
-
在python中你可以做到 def my_string(size): out_string = ('yn' * size)[:size] return out_string In python you can simply do def my_string(size): out_string = ('yn' * size)[:size] return out_string