Strip #@ script headers before loading Lua

LuaJIT now only treats a leading `#!` line as a shebang and interprets other
lines beginning with `#` as line number directives.

https://github.com/LuaJIT/LuaJIT/commit/c41d727dbffa5ec4f346dd9be0f4c64740f124aa
This commit is contained in:
meehl committed 2026-10-21 17:45:11 +02:00
1 parent a1e92fa94e
commit 4b997447b5
4 files changed
+52 -13

No files matched your search

+12 -8
View File
@@ -1,4 +1,7 @@
use crate::{pob::Context, util::change_working_directory};
use crate::{
pob::Context,
util::{change_working_directory, load_lua_file},
};
use mlua::{Function, IntoLuaMulti, Lua, MultiValue, Result as LuaResult, Value};
use std::env;
@@ -23,7 +26,7 @@ pub fn load_module(l: &Lua, (name, args): (String, MultiValue)) -> LuaResult<Mul
let current_dir = env::current_dir()?;
change_working_directory(script_dir.as_path())?;
let result = l.load(module_path).call::<MultiValue>(args);
let result = load_lua_file(l, &module_path).and_then(|chunk| chunk.call::<MultiValue>(args));
change_working_directory(current_dir)?;
result
}
@@ -40,12 +43,13 @@ pub fn protected_load_module(l: &Lua, (name, args): (String, MultiValue)) -> Lua
let current_dir = env::current_dir()?;
change_working_directory(script_dir.as_path())?;
let result = match l.load(module_path).call::<MultiValue>(args) {
// on success, callers expect a Nil followed by return values
Ok(res) => Ok(std::iter::once(Value::Nil).chain(res).collect()),
// otherwise it is set to error message.
Err(err) => err.to_string().into_lua_multi(l),
};
let result =
match load_lua_file(l, &module_path).and_then(|chunk| chunk.call::<MultiValue>(args)) {
// on success, callers expect a Nil followed by return values
Ok(res) => Ok(std::iter::once(Value::Nil).chain(res).collect()),
// otherwise it is set to error message.
Err(err) => err.to_string().into_lua_multi(l),
};
change_working_directory(current_dir)?;
result
}
+6 -1
View File
@@ -1,4 +1,7 @@
use crate::{pob::modules, util::append_lua_package_dir};
use crate::{
pob::modules,
util::{append_lua_package_dir, fix_script_header},
};
use anyhow::{Result, anyhow};
use mlua::{Integer, IntoLuaMulti, Lua, MultiValue, Number, Value};
use std::{
@@ -184,6 +187,8 @@ impl Subscript {
)?;
}
let mut script_text = script_text.into_bytes();
fix_script_header(&mut script_text);
let result = lua.load(script_text).call::<MultiValue>(arguments)?;
result.try_into()
});