浪語:修订间差异

无编辑摘要
无编辑摘要
无编辑摘要
标签2017年版源代码编辑
 
(未显示同一用户的5个中间版本)
第1行: 第1行:
 一種 JavaScript 的方言,因為由浪打所創因而得名。
 一種 JavaScript 的方言,因為由浪打所創因而得名。


 目前你可以在浪打所作的[https://chrome.google.com/webstore/detail/drrr-chatbot-extension/fkmpnkcjocenkliehpdhlfbmdmdnokgm 聊天插件]上 使用他。(如果 牆,可以參考[https://share.weiyun.com/1z7BPluA 這裡]
 目前你可以在浪打所作的 [[浪打聊天插件|聊天插件]] 上使用他。
 
此手冊目前還有 [https://hackmd.io/@nobodyzxc/SkoZau-Qd/https%3A%2F%2Fhackmd.io%2FVKZIZxRJQ4yPT-FElCa1GQ HackMD 線上板手冊中文版] (更好的閱讀體驗,但須翻牆)
 
在 HackMD  有 [https://hackmd.io/@nobodyzxc/SkoZau-Qd/https%3A%2F%2Fhackmd.io%2F8tO-FVCJSCGpRPoRDd1Uig English Manual].


[[File:Lambda language.png|每三十秒使用一言 API 換一次部屋描述。|有框|链接=Special:FilePath/Lambda_language.png]]
[[File:Lambda language.png|每三十秒使用一言 API 換一次部屋描述。|有框|链接=Special:FilePath/Lambda_language.png]]
第130行: 第134行:


// 還有一些幫你抓好的變數
// 還有一些幫你抓好的變數
loc // 現在位置(大廳或房間 "lounge" / "room")
drrr.loc // 現在位置(大廳或房間 "lounge" / "room")
profile // 個人訊息
drrr.profile // 個人訊息
room // 房間訊息
drrr.room // 房間訊息
users // 房間成員
drrr.users // 房間成員
info // 跟個人訊息有點像
drrr.info // 跟個人訊息有點像
rooms // 所有房間,大廳狀態
drrr.rooms // 所有房間,大廳狀態


// 有時你會需要更新,可以透過以下函數去更新他們
// 有時你會需要更新,可以透過以下函數去更新他們
updateLounge(callback);
drrr.getLounge(callback);
updateProfile(callback);
drrr.getProfile(callback);
updateLoc(callback);
drrr.getLoc(callback);


</syntaxhighlight>
</syntaxhighlight>
第188行: 第192行:
// 冒號 (:) 後面是 RegExp,如果匹配才呼叫。
// 冒號 (:) 後面是 RegExp,如果匹配才呼叫。
// 適用於 user 和 content (第一和第二個參數)
// 適用於 user 和 content (第一和第二個參數)
event msg (user: "lambda", content, url, tripcode, req){
event msg (user: "lambda", content, url, tripcode, req) => {
    drrr.print(user + " 叫了一下");
    drrr.print(user + " 叫了一下");
}
}


// 參數個數和名稱都可以任意,看你需求
// 參數個數和名稱都可以任意,看你需求
event join (user){
event join (user) => {
    drrr.print("welcome " + user);
    drrr.print("welcome " + user);
}
}
第216行: 第220行:
}
}


// 等價於第一個範例
// parse error, 10000() is not a function call
timer 10000 () => {
timer 10000 () => {
    print("hello world");
    print("hello world");
第231行: 第235行:
later 3000 f // 不會被呼叫,因為 f 被 auto lift,又被包了一層 function 在外面
later 3000 f // 不會被呼叫,因為 f 被 auto lift,又被包了一層 function 在外面
later 3000 f() // 這樣才會在三秒後印出 hello world
later 3000 f() // 這樣才會在三秒後印出 hello world
later 3000 () => console.log("hello world") // 但這個會正常運作
later 3000 () => console.log("hello world") // parse error, 3000() is not a function call
later 3000; () => console.log("hello world") // works, good
later 3000; (a, b) => console.log("hello world") // fine, too
later 3000 console.log("hello world") // 這個也會正常運作
later 3000 console.log("hello world") // 這個也會正常運作
later 3000 {
later 3000 {
第238行: 第244行:
</syntaxhighlight>
</syntaxhighlight>


 ※ 注意 timer 和 later 會將 "非 lambda 的 expression" lift 成一個 lambda。
 ※ 注意 timer 和 later 會將 "非 lambda 的 expression" lift 成一個 lambda expression,然後時間到了再 eval 他


 一些功能實作:
 一些功能實作:
第245行: 第251行:


<syntaxhighlight lang="javascript" line="1">
<syntaxhighlight lang="javascript" line="1">
guests = users.map((x)=>x.name);
guests = drrr.users.map((x)=>x.name);
event join (user) => {
event join (user) => {
   if guests.includes(user)
   if guests.includes(user)
第291行: 第297行:
// 房間上限 9.0001 人
// 房間上限 9.0001 人
event join (user) => {
event join (user) => {
   if users.length == 10
   if drrr.users.length == 10
   then
   then
   drrr.print("/me恭喜成為 0.0001 人,你終於不做人類了嗎!");
   drrr.print("/me恭喜成為 0.0001 人,你終於不做人類了嗎!");
   else
   else
drrr.print("/me歡迎第 " + String(users.length) + " 個貴賓!");
drrr.print("/me歡迎第 " + String(drrr.users.length) + " 個貴賓!");
}
}
</syntaxhighlight>
</syntaxhighlight>
153

个编辑