首页 \ 问答 \ Lua,WOW和“......”(Lua, WOW and “…”)

Lua,WOW和“......”(Lua, WOW and “…”)

让我的脚在Lua中湿透, 为魔兽世界编写一些简单的插件。 主要通过其他插件查看,检查代码等。我看到一件令我困惑的事情。 我知道...是一种将可变数量的参数传递给函数的方法,但我看到它在.lua文件的开头使用:

local parent, ns = ...

同样,这是源代码中的第一行。 我在文件中看到的唯一引用是在.xml文件中,作为脚本包含在内

<Ui>
    <Script file="unitframes\options\ouf.lua"/>
</Ui>

我很好奇传入的价值来自......

回答:

如下面的答案所示,WoW将参数传递给脚本。 显然,WoW将以下参数传递给脚本:

  1. AddOn的名称作为字符串(实际上是文件夹名称)
  2. 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:

  1. Name of the AddOn as a String (actually the folder name)
  2. 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
更新时间:2022-08-10 21:08

最满意答案

有几种不同的方法可以构建一行具有可变列数的输出。 哪一个最好可能取决于你在更大范围内实际做了什么。

一种简单的方法是循环遍历列值并对每个值进行print调用,并将关键字 - 仅参数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 print call for each one with the keyword-only argument 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 regular print() 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

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。