Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic support for MoonScript. #475

Merged
merged 6 commits into from
Apr 10, 2024
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
13 changes: 10 additions & 3 deletions ElunaLoader.cpp
Rochet2 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ void ElunaLoader::ReadFiles(lua_State* L, std::string path)
{
lua_requirepath +=
path + "/?.lua;" +
path + "/?.ext;";
path + "/?.ext;" +
path + "/?.moon;";

lua_requirecpath +=
path + "/?.dll;" +
Expand Down Expand Up @@ -196,7 +197,13 @@ void ElunaLoader::ReadFiles(lua_State* L, std::string path)
bool ElunaLoader::CompileScript(lua_State* L, LuaScript& script)
{
// Attempt to load the file
int err = luaL_loadfile(L, script.filepath.c_str());
int err = 0;
if (script.fileext == ".moon")
{
std::string str = "return require('moonscript').loadfile([[" + script.filepath+ "]])";
err = luaL_dostring(L, str.c_str());
} else
err = luaL_loadfile(L, script.filepath.c_str());

// If something bad happened, try to find an error.
if (err != 0)
Expand Down Expand Up @@ -234,7 +241,7 @@ void ElunaLoader::ProcessScript(lua_State* L, std::string filename, const std::s
filename = filename.substr(0, extDot);

// check extension and add path to scripts to load
if (ext != ".lua" && ext != ".ext")
if (ext != ".lua" && ext != ".ext" && ext != ".moon")
return;
bool extension = ext == ".ext";

Expand Down
2 changes: 1 addition & 1 deletion LuaEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void Eluna::OpenLua()
lua_getfield(L, -1, "searchers");
}
// insert the new loader to the loaders table by shifting other elements down by one
const int newLoaderIndex = 2;
const int newLoaderIndex = 1;
for (int i = lua_rawlen(L, -1); i >= newLoaderIndex; --i) {
lua_rawgeti(L, -1, i);
lua_rawseti(L, -2, i + 1);
Expand Down