Liquidsoap没有明确定义变量

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Liquidsoap没有明确定义变量相关的知识,希望对你有一定的参考价值。

好吧,我一直把头发拉了几个小时

Liquidsoap对我来说不起作用,而且我知道这应该可以工作,因为一个显而易见的错误...

set("log.file",false)
set("log.stdout",true)
set("log.level",3)

podcasts = playlist("/home/user/icecast/ham.txt")

# This function turns a fallible
# source into an infallible source
# by playing a static single when
# the original song is not available
def my_safe(radio) =
  # We assume that festival is installed and
  # functional in liquidsoap
  security = single("say:Hello, we are currently having some technical difficulties but we'll be back soon so stay tuned!")
  # We return a fallback where the original
  # source has priority over the security
  # single. We set track_sensitive to false
  # to return immediately to the original source
  # when it becomes available again.
  fallback(track_sensitive=false,[radio, security])
end

radio= podcasts
radio= my_safe(podcasts)

# A function that contains all the output
# we want to create with the final stream
def outputs(s) =
  # First, we partially apply output.icecast
  # with common parameters. The resulting function
  # is stored in a new definition of output.icecast,
  # but this could be my_icecast or anything.
  output.icecast = output.icecast(host="localhost", password="foobar")
  # An output in mp3 to the "live" mountpoint:
  output.icecast(%mp3, mount="live",radio)
end

而错误

At line 23, character 6: The variable radio defined here is not used anywhere
  in its scope. Use ignore(...) instead of radio = ... if you meant
  to not use it. Otherwise, this may be a typo or a sign that your script
  does not do what you intend.

如果有人也能解决我遇到的另一个问题

我想找到如何将两个源运行到两个单独的挂载点

set("log.file",false)
set("log.stdout",true)
set("log.level",3)

podcasts = playlist("/home/user/icecast/ham.txt")
songlist = playlist("/home/user/icecast/otherplaylist.txt")

# This function turns a fallible
# source into an infallible source
# by playing a static single when
# the original song is not available
def my_safe(radio) =
  # We assume that festival is installed and
  # functional in liquidsoap
  security = single("say:Hello, we are currently having some technical difficulties but we'll be back soon so stay tuned!")
  # We return a fallback where the original
  # source has priority over the security
  # single. We set track_sensitive to false
  # to return immediately to the original source
  # when it becomes available again.
  fallback(track_sensitive=false,[radio, security])
end

radio= podcasts
radio= my_safe(podcasts)

def my_safe(songlist) =
  # We assume that festival is installed and
  # functional in liquidsoap
  security = single("say:Hello, we are currently having some technical difficulties but we'll be back soon so stay tuned!")
  # We return a fallback where the original
  # source has priority over the security
  # single. We set track_sensitive to false
  # to return immediately to the original source
  # when it becomes available again.
  fallback(track_sensitive=false,[songlist, security])
end

moarradio= songlist
moarradio= my_safe(songlist)

# A function that contains all the output
# we want to create with the final stream
def outputs(s) =
  # First, we partially apply output.icecast
  # with common parameters. The resulting function
  # is stored in a new definition of output.icecast,
  # but this could be my_icecast or anything.
  output.icecast = output.icecast(host="localhost", password="foobar")
  # An output in mp3 to the "live" mountpoint:
  output.icecast(%mp3, mount="live",radio)

  output.icecast(%mp3, mount="otherlive",moarmusic)
end

我得到了同样的错误,但它告诉我没有使用第二个变量(moarradio)

答案

liquidsoap配置文件基本上是一个脚本,这意味着它将从上到下运行。

在阅读配置文件时,它抱怨你没有使用radio变量定义的第23行,原因是你正在使用一个定义的第24行。与许多其他语言不同,在liquidsoap脚本中有no assignments, only definitions

除此之外,您似乎无法理解全局变量和局部变量之间的差异,以及它们各自的范围。

你正在声明一个my_safe函数,它接受一个参数。在函数范围内,请使用其名称引用您的参数。然后使用全局变量作为参数调用my_safe函数,并且您实际会发生什么。

如果您不调用outputs函数,您的来源将不会被注册。简单地删除函数构造。

以下是我重写第二个例子的方法:

set("log.file",false)
set("log.stdout",true)
set("log.level",3)

podcasts = playlist("/home/user/icecast/ham.txt")
songlist = playlist("/home/user/icecast/otherplaylist.txt")

# This function turns a fallible
# source into an infallible source
# by playing a static single when
# the original song is not available
def my_safe(stream) =                          # <- used a different variable name here
  # We assume that festival is installed and
  # functional in liquidsoap
  security = single("say:Hello, we are currently having some technical difficulties but we'll be back soon so stay tuned!")
  # We return a fallback where the original
  # source has priority over the security
  # single. We set track_sensitive to false
  # to return immediately to the original source
  # when it becomes available again.
  fallback(track_sensitive=false,[stream, security])  # <- used a different variable name here
end

radio= my_safe(podcasts) # <- fix here

# <- got rid of redeclaration of my_safe

moarradio= my_safe(songlist) # <- fix here

# <- got rid of function construct
# First, we partially apply output.icecast
# with common parameters. The resulting function
# is stored in a new definition of output.icecast,
# but this could be my_icecast or anything.
output.icecast = output.icecast(host="localhost", password="foobar")
# An output in mp3 to the "live" mountpoint:
output.icecast(%mp3, mount="live",radio)
output.icecast(%mp3, mount="otherlive",moarradio)  # <- fix here

以上是关于Liquidsoap没有明确定义变量的主要内容,如果未能解决你的问题,请参考以下文章

Kotlin !!操作员使用使代码不清晰

Liquidsoap + JACK 延迟

Liquidsoap——读取元数据

为什么变量没有未定义?

GO学习笔记 - 变量在定义时没有明确的初始化时会赋值为“零值 ”。

9.13面经