v0.7 তৈরি হচ্ছেপ্রাথমিক পর্যায়ে
ActionScript-এর শিকড় থেকে আসা একটি কঠোর, স্ট্যাটিক্যালি টাইপড ভাষা
RuneScript ActionScript-এর package, trace, int/uint,
try/catch ও অ্যাক্সেস মডিফায়ার ধরে রাখে, সিনট্যাক্স নিয়ে আসে C-পরিবারের ধাঁচে, আর
প্রোগ্রাম চলার আগেই প্রতিটি টাইপ যাচাই করে। এটি Go-তে তৈরি একটি স্বতন্ত্র CLI হিসেবে চলে, এবং একই কঠোর
টাইপিং বজায় রেখে ওয়েবের জন্য একটি JavaScript মডিউলে কম্পাইল হয়।
- যে ভাষায় তৈরি
- Go 1.25+
- টাইপিং
- স্ট্যাটিক, স্পষ্ট
- যেভাবে চলে
- CLI, JavaScript ও WebAssembly
// The smallest complete RuneScript program.
package main;
protected int main() {
trace("Hello, RuneScript!");
return 0;
}$ runescript run hello.rsc
Hello, RuneScript!// Advanced functions: callbacks, lambdas, nested functions, prototypes,
// and functions that return functions.
package examples.callbacks;
// A prototype: the definition is further down.
public int sumWith(int(int) f, int n);
public void forEach(int from, int to, void(int) body) {
for (int i = from; i <= to; i++) {
body(i);
}
}
public int(int) multiplier(int factor) {
// Functions do not capture variables, so each factor gets its own function.
private int times2(int x) { return x * 2; }
private int times3(int x) { return x * 3; }
if (factor == 2) {
return times2;
}
if (factor == 3) {
return times3;
}
return (int x) => x;
}
protected int main() {
// Pass a lambda as a callback.
forEach(1, 3, (int i) => trace("item", i));
// Store functions in variables and pass named functions around.
int(int) square = (int x) => x * x;
trace("sum of squares 1..4:", sumWith(square, 4));
trace("sum of triples 1..5:", sumWith(multiplier(3), 5));
trace("double 21:", multiplier(2)(21));
// Nested functions, with a prototype for mutual recursion.
private bool isEven(int n);
private bool isOdd(int n) {
if (n == 0) { return false; }
return isEven(n - 1);
}
private bool isEven(int n) {
if (n == 0) { return true; }
return isOdd(n - 1);
}
trace("7 is odd:", isOdd(7));
return 0;
}
public int sumWith(int(int) f, int n) {
int total = 0;
for (int i = 1; i <= n; i++) {
total += f(i);
}
return total;
}$ runescript run callbacks.rsc
item 1
item 2
item 3
sum of squares 1..4: 30
sum of triples 1..5: 45
double 21: 42
7 is odd: true// The std:string standard library package (Go's strings, camelCase names).
package examples.strings;
use "std:string";
public string slug(string title) {
string s = string.toLower(string.trimSpace(title));
return string.replaceAll(s, " ", "-");
}
protected int main() {
string title = " Hello RuneScript World ";
trace("slug:", slug(title));
string path = "assets/runescript.svg";
if (string.hasSuffix(path, ".svg")) {
trace("image:", string.trimSuffix(path, ".svg"));
}
int slash = string.index(path, "/");
trace("first slash at byte", slash);
trace("vowels in title:", string.count(title, "o") + string.count(title, "e"));
trace(string.repeat("=", 20));
return 0;
}$ runescript run strings.rsc
slug: hello-runescript-world
image: assets/runescript
first slash at byte 6
vowels in title: 4
====================চেনা গড়ন, আরও কঠোর নিয়ম
ActionScript, Java, C# বা TypeScript লিখে থাকলে RuneScript ঠিক আপনার প্রত্যাশামতো পড়া যায়। শুধু এটি অনুমান করতে রাজি নয়।
আগে টাইপ, C-পরিবারের সিনট্যাক্স
লিখুন public int add(int a, int b)। প্রতিটি ফাংশন শুরু হয় একটি অ্যাক্সেস মডিফায়ার দিয়ে, টাইপ বসে নামের আগে, আর সেমিকোলন বাধ্যতামূলক।
শুরু থেকেই কঠোর
কোনো কিছুই নিজে থেকে any নয়। সাইনড ও আনসাইনড পূর্ণসংখ্যা কখনো নিঃশব্দে মেশে না, আর শর্তকে অবশ্যই bool হতে হবে।
নিঃশব্দ ওভারফ্লো নেই
পূর্ণসংখ্যার হিসাব নির্ভুল। ওভারফ্লো আর শূন্য দিয়ে ভাগ ঘুরে না গিয়ে, অবস্থানসহ একটি রানটাইম এরর দিয়ে প্রোগ্রাম থামিয়ে দেয়।
যে এরর সমস্যাটি দেখিয়ে দেয়
প্রতিটি ডায়াগনস্টিকে আছে একটি স্থায়ী কোড, লাইন ও কলাম, ক্যারেট-চিহ্নসহ সোর্সের লাইনটি, আর কীভাবে ঠিক করবেন তা বলে দেওয়া সাহায্য-বার্তা।
মান হিসেবে ফাংশন
int(int, int)-এর মতো ফাংশন টাইপ, ল্যাম্বডা, কলব্যাক, নেস্টেড ফাংশন, প্রোটোটাইপ, এবং যে ফাংশন ফাংশন ফেরত দেয়।
যে ডকস কম্পাইল হয়
গাইডের প্রতিটি প্রোগ্রাম টেস্ট-সংগ্রহ কম্পাইল করে, আর প্রতিটি উদাহরণের আউটপুট যাচাই করা হয়। ডকস কোড থেকে সরে গেলে বিল্ড ব্যর্থ হয়।
প্রোগ্রাম চলার আগেই ভুল ধরা পড়ে
একটি সাইনড মান uint-এ অ্যাসাইন করা কম্পাইলের সময়ের এরর, নিঃশব্দে ঘুরে যাওয়া নয়। চেকার ঠিক
কোথায় সমস্যা, আর কী করতে হবে, তা জানিয়ে দেয়।
- স্থায়ী এরর কোড, যেমন
ASX-TYPE-004 -
line:colঅবস্থান, সোর্সের লাইন ও একটি ক্যারেট-চিহ্নসহ - নির্দিষ্ট সমাধানসহ সাহায্য-বার্তা
package examples.errors;
protected int main() {
sint signedValue = -10;
uint unsignedValue = signedValue; // expect: ASX-TYPE-004 9:26
return 0;
}$ runescript check signedness_error.rsc
examples/signedness_error.rsc:9:26: error ASX-TYPE-004: Cannot assign signed integer 'sint' to unsigned integer 'uint'.
uint unsignedValue = signedValue; // expect: ASX-TYPE-004 9:26
^^^^^^^^^^^
help: Use an explicit checked conversion, (uint) x, or change the destination type.ActionScript 3 থেকে আসছেন?
RuneScript AS3 থেকে অনুপ্রাণিত, কিন্তু সোর্স-স্তরে এর সঙ্গে সামঞ্জস্যপূর্ণ নয়। ঘোষণায় টাইপ আগে আসে, আর কোনো function বা var নেই।
ActionScript 3
package {
public class Greeter {
public function sayHi(message:String, times:int):void {
for (var i:int = 0; i < times; i++) {
trace(message);
}
}
}
}RuneScript
package main;
public void sayHi(string message, int times) {
for (int i = 0; i < times; i++) {
trace(message);
}
}
protected int main() {
sayHi("hi", 2);
return 0;
}| কোড | ActionScript 3 | RuneScript |
|---|---|---|
var u:uint = -1; | হয়ে যায় 4294967295 | কম্পাইল এরর ASX-TYPE-007 |
uint ← int ভেরিয়েবল | নিঃশব্দে রূপান্তরিত হয় | কম্পাইল এরর ASX-TYPE-004 |
int + uint | নিঃশব্দে রূপান্তরিত হয় | কম্পাইল এরর ASX-TYPE-011 |
int.MAX_VALUE + 1 | ঘুরে একটি ঋণাত্মক সংখ্যা হয়ে যায় | রানটাইম এরর ASX-RUN-002 |
7 / 2 | 3.5 | 3 (পূর্ণসংখ্যার ভাগ) |
এখন কোথায় দাঁড়িয়ে
RuneScript ইচ্ছে করেই ছোট। কোনো বৈশিষ্ট্য তখনই সম্পূর্ণ ধরা হয়, যখন টেস্ট দেখায় যে সেটি কাজ করে।
এখন কাজ করে
- প্যাকেজ, আর অ্যাক্সেস মডিফায়ারসহ ফাংশন
- int / sint, uint, float / float32 / float64, bool, string, void
- if, while, for, for each, break, continue, return
- ফাংশন টাইপ, ল্যাম্বডা, কলব্যাক
- use "std:string" (Go-র strings প্যাকেজ, split, join ও কলব্যাকসহ)
- স্ট্রিং: + ও $"{count} files"; char; যাচাই করা ইনডেক্সসহ Array<T>
- int8 … uint64, হেক্স ও বাইনারি লিটারাল, বিট অপারেটর
- use "std:math", দুটি টার্গেটে বিট-বিট এক ফলসহ
- স্ট্রাক্ট: মান-টাইপ, মেথড ও কনস্ট্রাক্টর
- মডিউল ফাইলের জন্য SemVer মেটাডেটা
- CLI প্রোগ্রাম চালাতে Go ক্লোজার
- raylib দিয়ে ডেস্কটপ ও ব্রাউজারে গ্রাফিক্স
- ক্লাস: ফিল্ড, মেথড, কনস্ট্রাক্টর; new দিয়ে তৈরি, রেফারেন্স হিসেবে শেয়ার করা অবজেক্ট
- একাধিক ফাইলের প্রোগ্রাম: use "pkg" ও use "./file"
- ফাইল, ইনপুট ও আর্গুমেন্ট: use "std:fs", "std:io", "std:process", "std:path"
- ডেটা: use "std:json", "std:csv", "std:matrix", "std:semver"
- যাচাই করা রূপান্তর: (int) 64.3, (float) "64.7"
- throw, try / catch / finally, ধরা যায় এমন রানটাইম এরর
- অবস্থানসহ কম্পাইল-টাইম ও রানটাইম এরর
- JavaScript-এ কম্পাইল (runescript build), সোর্স ম্যাপসহ
- extern দিয়ে JavaScript কল, ফেরত আসা প্রতিটি মান যাচাই করে
- সতর্কবার্তা, -Werror ও --allow সহ
- লাইভ রিলোড: runescript dev, run --watch
- ওয়েব পেজ: যাচাই করা HTML/SVG টেমপ্লেট, $foreach তালিকা, রুন (সিগন্যাল), ইভেন্ট
- এডিটর: VS Code, Vim, Neovim, Emacs, ল্যাঙ্গুয়েজ সার্ভারের মাধ্যমে (runescript lsp)
পরিকল্পিত
- ক্লাসের ইনহেরিট্যান্স ও ইন্টারফেস
- গ্রাফিক্স প্যাকেজে অডিও
- ওয়ার্কস্পেস জুড়ে নাম বদল
আপনার প্রথম প্রোগ্রাম চালান
আপনার Go 1.25 বা নতুনতর লাগবে। CLI তৈরি করুন, তারপর যেকোনো উদাহরণ চালান।
সোর্স নিন
$ git clone https://github.com/AurielSolaris/runescript.git && cd runescriptCLI তৈরি করুন
$ go build -o runescript ./cmd/runescriptএকটি প্রোগ্রাম চালান
$ ./runescript run examples/hello.rsc Hello, RuneScript!