Skip to content

Commit

Permalink
Add basic support for MoonScript. (#475)
Browse files Browse the repository at this point in the history
Co-authored-by: Rochet2 <rochet2@post.com>
  • Loading branch information
iThorgrim and Rochet2 authored Apr 10, 2024
1 parent 8b80ef4 commit a60f1ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions ElunaLoader.cpp
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

0 comments on commit a60f1ea

Please sign in to comment.