|
28 | 28 | #include "lua/luawrapper.h"
|
29 | 29 | #include "support/file.h"
|
30 | 30 | #include "support/strings-helpers.h"
|
| 31 | +#include "support/djbhash.h" |
31 | 32 | #include "support/zip.h"
|
32 | 33 |
|
33 | 34 | namespace {
|
@@ -81,6 +82,30 @@ PCSX::File* load(std::string_view name, std::string_view from, bool inArchives =
|
81 | 82 | return new PCSX::PosixFile(absolutePath);
|
82 | 83 | }
|
83 | 84 |
|
| 85 | +uint64_t djbHash(const char* str, size_t len) { |
| 86 | + return PCSX::djb::hash(str, len); |
| 87 | +} |
| 88 | + |
| 89 | +template <typename T, size_t S> |
| 90 | +void registerSymbol(PCSX::Lua L, const char (&name)[S], const T ptr) { |
| 91 | + L.push<S>(name); |
| 92 | + L.push((void*)ptr); |
| 93 | + L.settable(); |
| 94 | +} |
| 95 | + |
| 96 | +#define REGISTER(L, s) registerSymbol(L, #s, s) |
| 97 | + |
| 98 | +void registerAllSymbols(PCSX::Lua L) { |
| 99 | + L.getfieldtable("_CLIBS", LUA_REGISTRYINDEX); |
| 100 | + L.push("SUPPORT_EXTRA"); |
| 101 | + L.newtable(); |
| 102 | + |
| 103 | + REGISTER(L, djbHash); |
| 104 | + |
| 105 | + L.settable(); |
| 106 | + L.pop(); |
| 107 | +} |
| 108 | + |
84 | 109 | } // namespace
|
85 | 110 |
|
86 | 111 | PCSX::ZipArchive& PCSX::LuaFFI::addArchive(Lua L, IO<File> file) {
|
@@ -138,6 +163,7 @@ void PCSX::LuaFFI::open_extra(Lua L) {
|
138 | 163 | static const char* extra = (
|
139 | 164 | #include "lua/extra.lua"
|
140 | 165 | );
|
| 166 | + registerAllSymbols(L); |
141 | 167 | L.load(pprint, "third_party:pprint.lua/pprint.lua");
|
142 | 168 | L.load(pprint_internals, "third_party:pprint.lua/pprint-internals.lua");
|
143 | 169 | L.load(reflectFFI, "third_party:ffi-reflect/reflect.lua");
|
|
0 commit comments