Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ CodeForge 是一款轻量级、高性能的桌面代码执行器,专为开发
<img src="public/icons/javascript-jquery.svg" width="60" alt="JavaScript (jQuery)">
<img src="public/icons/javascript-nodejs.svg" width="60" alt="JavaScript (Node.js)">
<img src="public/icons/kotlin.svg" width="60" alt="Kotlin">
<img src="public/icons/lua.svg" width="60" alt="Lua">
<img src="public/icons/nodejs.svg" width="60" alt="Node.js">
<img src="public/icons/php.svg" width="60" alt="PHP">
<img src="public/icons/python.svg" width="60" alt="Python 2">
Expand Down
5 changes: 5 additions & 0 deletions public/icons/lua.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions src-tauri/src/examples/lua.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
-- Lua 示例代码 - CodeForge 代码执行环境

print("🎉 欢迎使用 CodeForge!")
print("Welcome to CodeForge!")
print("")

print("=========================================")
print(" CodeForge Lua ")
print("=========================================")
print("")

-- 基本输出示例
print("✅ Lua运行成功! (Lua is working!)")
print("⚡ 这是Lua程序 (This is Lua program)")
print("")

-- 变量操作
local name = "CodeForge"
local version = "Lua"
local number1 = 10
local number2 = 20
local result = number1 + number2

print("🔢 简单计算 (Simple calculation):")
print(string.format("%d + %d = %d", number1, number2, result))
print("")

-- 字符串操作
print("📝 字符串操作 (String operations):")
print("平台名称 (Platform): " .. name)
print("语言版本 (Language): " .. version)
print("完整信息 (Full info): " .. name .. " - " .. version)
print("")

-- 表(数组)操作
print("🍎 表示例 (Table example):")
local fruits = {"苹果", "香蕉", "橙子", "葡萄"}
for i, fruit in ipairs(fruits) do
print(string.format("%d. %s", i, fruit))
end
print("")

-- 条件判断
local score = 85
print("📊 成绩评估 (Score evaluation):")
if score >= 90 then
print("优秀! (Excellent!)")
elseif score >= 80 then
print("良好! (Good!)")
elseif score >= 60 then
print("及格 (Pass)")
else
print("需要努力 (Need improvement)")
end
print("")

-- 循环示例
print("🔄 循环输出 (Loop output):")
for i = 1, 5 do
print(string.format("第 %d 次输出 (Output #%d): Hello from CodeForge!", i, i))
end
print("")

-- while循环示例
print("🔁 While循环示例 (While loop example):")
local counter = 1
while counter <= 3 do
print(string.format("While循环: 第 %d 次", counter))
counter = counter + 1
end
print("")

-- 函数示例
local function greet(msg)
return "🎯 " .. msg
end

print(greet("CodeForge Lua代码执行完成!"))
print(greet("CodeForge Lua execution completed!"))
print("")
print("感谢使用 CodeForge 代码执行环境! 🚀")
print("Thank you for using CodeForge! 🚀")
82 changes: 82 additions & 0 deletions src-tauri/src/plugins/lua.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use super::{LanguagePlugin, PluginConfig};
use std::vec;

pub struct LuaPlugin;

impl LanguagePlugin for LuaPlugin {
fn get_order(&self) -> i32 {
26
}

fn get_language_name(&self) -> &'static str {
"Lua"
}

fn get_language_key(&self) -> &'static str {
"lua"
}

fn get_file_extension(&self) -> String {
self.get_config()
.map(|config| config.extension.clone())
.unwrap_or_else(|| "lua".to_string())
}

fn get_version_args(&self) -> Vec<&'static str> {
vec!["-v"]
}

fn get_path_command(&self) -> String {
"which lua".to_string()
}

fn get_command(
&self,
_file_path: Option<&str>,
_is_version: bool,
_file_name: Option<String>,
) -> String {
if _is_version {
let lua_command = if self.get_execute_home().is_some() {
"./lua"
} else {
"lua"
};

return lua_command.to_string();
}

// 执行代码时
if let Some(config) = self.get_config() {
if let Some(run_cmd) = &config.run_command {
return if let Some(file_name) = _file_name {
run_cmd.replace("$filename", &file_name)
} else {
run_cmd.clone()
};
}
}
self.get_default_command()
}

fn get_default_config(&self) -> PluginConfig {
PluginConfig {
enabled: true,
language: String::from("lua"),
before_compile: None,
extension: String::from("lua"),
execute_home: None,
run_command: Some(String::from("lua $filename")),
after_compile: None,
template: Some(String::from("-- Lua 示例代码 - CodeForge 代码执行环境\n\n")),
timeout: Some(30),
console_type: Some(String::from("console")),
}
}

fn get_default_command(&self) -> String {
self.get_config()
.and_then(|config| config.run_command.clone())
.unwrap_or_else(|| "lua".to_string())
}
}
2 changes: 2 additions & 0 deletions src-tauri/src/plugins/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::plugins::javascript_browser::JavaScriptBrowserPlugin;
use crate::plugins::javascript_jquery::JavaScriptJQueryPlugin;
use crate::plugins::javascript_nodejs::JavaScriptNodeJsPlugin;
use crate::plugins::kotlin::KotlinPlugin;
use crate::plugins::lua::LuaPlugin;
use crate::plugins::nodejs::NodeJSPlugin;
use crate::plugins::php::PHPPlugin;
use crate::plugins::python2::Python2Plugin;
Expand Down Expand Up @@ -62,6 +63,7 @@ impl PluginManager {
plugins.insert("r".to_string(), Box::new(RPlugin));
plugins.insert("cangjie".to_string(), Box::new(CangjiePlugin));
plugins.insert("haskell".to_string(), Box::new(HaskellPlugin));
plugins.insert("lua".to_string(), Box::new(LuaPlugin));
plugins.insert(
"javascript-nodejs".to_string(),
Box::new(JavaScriptNodeJsPlugin),
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ pub mod javascript_browser;
pub mod javascript_jquery;
pub mod javascript_nodejs;
pub mod kotlin;
pub mod lua;
pub mod manager;
pub mod nodejs;
pub mod php;
Expand Down
3 changes: 3 additions & 0 deletions src/composables/useCodeMirrorEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {ruby} from '@codemirror/legacy-modes/mode/ruby'
import {groovy} from '@codemirror/legacy-modes/mode/groovy'
import {r} from "@codemirror/legacy-modes/mode/r"
import {haskell} from "@codemirror/legacy-modes/mode/haskell"
import {lua} from "@codemirror/legacy-modes/mode/lua"
import {
abcdef,
abyss,
Expand Down Expand Up @@ -216,6 +217,8 @@ export function useCodeMirrorEditor(props: Props)
return StreamLanguage.define(r)
case 'haskell':
return StreamLanguage.define(haskell)
case 'lua':
return StreamLanguage.define(lua)
default:
return null
}
Expand Down
Loading