| 445 | } |
| 446 | |
| 447 | ByteArray LuaEngine::compile(char const* contents, size_t size, char const* name) { |
| 448 | lua_checkstack(m_state, 1); |
| 449 | |
| 450 | handleError(m_state, luaL_loadbuffer(m_state, contents, size, name)); |
| 451 | |
| 452 | ByteArray compiledScript; |
| 453 | lua_Writer writer = [](lua_State*, void const* data, size_t size, void* byteArrayPtr) -> int { |
| 454 | ((ByteArray*)byteArrayPtr)->append((char const*)data, size); |
| 455 | return 0; |
| 456 | }; |
| 457 | lua_dump(m_state, writer, &compiledScript, false); |
| 458 | lua_pop(m_state, 1); |
| 459 | |
| 460 | return compiledScript; |
| 461 | } |
| 462 | |
| 463 | ByteArray LuaEngine::compile(String const& contents, String const& name) { |
| 464 | return compile(contents.utf8Ptr(), contents.utf8Size(), name.empty() ? nullptr : name.utf8Ptr()); |