function f(...)
return ...
end
Run Code Online (Sandbox Code Playgroud)
我称之为:
f()
Run Code Online (Sandbox Code Playgroud)
例
a = f()
print(a) -- echoes 'nil', same as print(nil)
Run Code Online (Sandbox Code Playgroud)
但
print(f()) -- echoes newline, same as print(), that is, no args
t = {f()} -- same as t = {}
Run Code Online (Sandbox Code Playgroud)
那么,f()返回什么?
更新:不知道函数可以返回'void',同时发现这个http://lua-users.org/lists/lua-l/2011-09/msg00289.html.
我有一个std::wstring decode(const char *s)功能.
我这样使用它:
const char *src = "some string";
const wchar_t *result = decode(src).c_str();
Run Code Online (Sandbox Code Playgroud)
我总是得到垃圾result[0],有时result[1]也是垃圾.
当我以另一种方式使用它时,我不会得到垃圾:
std::wstring res = decode(src);
const wchar_t *result = res.c_str();
Run Code Online (Sandbox Code Playgroud)
我的decode功能定义如下,它确实起作用了.唯一的问题是调用代码(上图).
std::wstring decode(const char *s, UINT cp=CP_ACP)
{
if(s == NULL)
return std::wstring();
int length = ::MultiByteToWideChar(cp, 0, s, -1, NULL, 0 );
wchar_t *buf = new wchar_t[length];
::MultiByteToWideChar(cp, 0, s, -1, buf, length);
std::wstring r(buf);
delete[] buf;
return r;
}
Run Code Online (Sandbox Code Playgroud)
我使用Visual C++ 2008 SP1进行编译.