Skip to content

Instantly share code, notes, and snippets.

@imring
Created April 4, 2021 12:44
Show Gist options
  • Save imring/70ed64fd7b699c59983496d4f1d31cff to your computer and use it in GitHub Desktop.
Save imring/70ed64fd7b699c59983496d4f1d31cff to your computer and use it in GitHub Desktop.
#include <filesystem>
#include <fstream>
#include <iostream>
#include <fmt/core.h>
#include <fmt/os.h>
#include "bclist.hpp"
namespace fs = std::filesystem;
void print_info(std::string_view str) {
fs::path filename = str;
if (!fs::is_regular_file(filename)) {
fmt::print(stderr, "The path isn't a file.\n");
return;
}
std::ifstream luac(filename, std::ios::binary);
if (luac.fail()) {
fmt::print(stderr, "Error opening file.\n");
return;
}
dislua::buffer buf((std::istreambuf_iterator<char>(luac)),
std::istreambuf_iterator<char>());
auto info = dislua::read_all(buf);
luac.close();
if (!info) {
fmt::print(stderr, "Unknown compiler of lua script.\n");
return;
}
fs::path new_filename = filename.stem();
new_filename += fs::path("-bclist.lua");
filename.replace_filename(new_filename);
bclist list = bclist::get_list(info.get());
auto out = fmt::output_file(filename.string());
out.print("{}", list.full());
}
int main(int argc, char *argv[]) {
if (argc != 2) {
std::cout << "USAGE: bclist [file]\n";
return 0;
}
print_info(argv[1]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment