小编Hen*_*gen的帖子

在Lua中读取整个文件

我想读取一个完整的mp3文件,以便读出id3标签.就在那时我注意到那个文件:read("*a")显然不会读取整个文件而是一小部分.所以我尝试构建某种解决方法以获取整个文件的内容:

function readAll(file)
    local f = io.open(file, "r")
    local content = ""
    local length = 0

    while f:read(0) ~= "" do
        local current = f:read("*all")

        print(#current, length)
        length = length + #current

        content = content .. current
    end

    return content
end
Run Code Online (Sandbox Code Playgroud)

对于我的testfile,这表明执行了256次读取操作,总共读取了~113kB(整个文件大约为7MB).虽然这应该足以读取大多数id3标签,但我想知道为什么Lua会以这种方式运行(特别是因为它在读取大型基于文本的文件时不会,例如*.oj或*.ase).是否有任何解释这种行为或可能是一个可靠的读取整个文件的解决方案?

io lua

18
推荐指数
1
解决办法
3万
查看次数

从UWP和ASP.NET 5引用类库

我正在尝试创建一个类库,它将包含WebAPI(使用ASP.NET 5)和消费UWP App的公共对象(主要是DTO).但是,我还没有想出如何创建类库,以便可以从其他项目中引用它.

到目前为止
我尝试过:首先,我尝试了一个类库(包),它可以在Web下找到.可以从ASP.NET项目中引用这种类型的库而不会出现问题,但是当尝试从UWP项目引用它时,我收到以下消息:

A reference to 'ClassLibrary1' could not be added. 
Run Code Online (Sandbox Code Playgroud)

接下来,我尝试了一个类库(Windows Universal),它可以在Windows> Universal下找到.这可以很容易地从UWP项目中引用,但是当尝试从ASP.NET引用它时,我得到:

The following projects are not supported as references : 

  - The project ClassLibrary2 has a target framework that is incompatible or has version higher than the current project and cannot be referenced.
Run Code Online (Sandbox Code Playgroud)

那么:我如何创建一个可以在ASP.NET 5项目 UWP项目中使用的类库?

project.json uwp asp.net-core

9
推荐指数
2
解决办法
2344
查看次数

Xamarin.Forms中的实体框架7

实体框架7目前作为Beta版本提供,本文指出在Xamarin项目中使用Entity Framework 7是可能的(将会是?).

但是,当我尝试使用NuGet安装它时:

Install-Package EntityFramework.SQLite –Pre
Run Code Online (Sandbox Code Playgroud)

它会失败:

Install-Package : Could not install package 'EntityFramework.Sqlite 7.0.0-beta6'. You are trying to install this package into a 
project that targets '.NETPortable,Version=v4.5,Profile=Profile78', but the package does not contain any assembly references or 
content files that are compatible with that framework. For more information, contact the package author.
At line:1 char:1
+ Install-Package EntityFramework.SQLite –Pre
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Run Code Online (Sandbox Code Playgroud)

有没有办法在Xamarin项目中使用Entity Framework,还是我必须坚持使用sqlite-net …

c# entity-framework xamarin xamarin.forms

7
推荐指数
1
解决办法
7746
查看次数

在Lua中收到"清除"错误消息

我在我的很多error函数中使用该函数,并希望将错误消息传播给用户.但是,我显然不希望包含有关错误发生位置的信息; 此信息应仅转到日志文件.

例如,我有一个管理服务器连接的类.如果连接超时,则调用

error("Connection timed out!")
Run Code Online (Sandbox Code Playgroud)

然后通过调用代码捕获错误消息pcall.但是,该消息不仅包含我传递的消息,还包含导致错误的文件名和行号:

common/net/enetclient.lua:21: Connection timed out!
Run Code Online (Sandbox Code Playgroud)

问题是:有没有办法只检索错误消息本身,或者我必须手动执行此操作,如下所示:

local status, msg = pcall(someFunctionThatThrowsErrors)
if not status then
    local file, msg = msg:match("(.-:%d+): (.+)")
    print("Error: " .. msg)
end
Run Code Online (Sandbox Code Playgroud)

干杯,

error-handling lua

5
推荐指数
1
解决办法
496
查看次数

使用资源定义厚度

在Windows应用程序UWP项目,我试图将其分配给它的定义厚度Left,Top,RightBottom属性:

<Setter Property="Margin">
    <Setter.Value>
        <Thickness Left="{StaticResource SomeDouble}"
                   Top="0"
                   Right="0"
                   Bottom="0" />
    </Setter.Value>
</Setter>
Run Code Online (Sandbox Code Playgroud)

这个答案似乎表明这在WPF中是可能的,但是,在我的UWP项目(以及WinRT应用程序)中,我收到以下错误:

XAML Thickness type cannot be constructed. 
In order to be constructed in XAML, a type cannot be abstract, interface, nested, generic 
or a struct, and must have a public default constructor.
Run Code Online (Sandbox Code Playgroud)

有没有办法使用资源定义厚度?

xaml windows-runtime uwp

3
推荐指数
1
解决办法
1872
查看次数

LuaSocket需要超级用户来创建服务器

当我尝试在Ubuntu上使用LuaSocket创建一个侦听任何端口的套接字时,套接字的创建失败并显示"权限被拒绝":

require("socket")

server, msg = socket.bind("*", 23)

if not server then print(msg) end
Run Code Online (Sandbox Code Playgroud)

但是,当以超级用户(使用sudo)执行相同的脚本时,服务器的创建工作正常.有没有理由说LuaSocket无法正常创建服务器?我可以做任何事情(在Lua或Ubuntu服务器上),这样就不需要以超级用户身份执行脚本了吗?

lua serversocket luasocket

0
推荐指数
1
解决办法
335
查看次数