mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2025-09-06 00:42:05 +02:00
add LuaEngine compiler
This commit is contained in:
parent
adb091dfbb
commit
eec5071578
9 changed files with 225 additions and 20 deletions
34
src/luaenginec/luaenginec.pro
Normal file
34
src/luaenginec/luaenginec.pro
Normal file
|
@ -0,0 +1,34 @@
|
|||
#/*****************************************************************************
|
||||
#* luaEngine Lua Engine for Qt
|
||||
#* Copyright (C) 2019 Syping
|
||||
#*
|
||||
#* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
#* you may not use this file except in compliance with the License.
|
||||
#* You may obtain a copy of the License at
|
||||
#*
|
||||
#* http://www.apache.org/licenses/LICENSE-2.0
|
||||
#*
|
||||
#* Unless required by applicable law or agreed to in writing, software
|
||||
#* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
#* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#* See the License for the specific language governing permissions and
|
||||
#* limitations under the License.
|
||||
#*****************************************************************************/
|
||||
|
||||
QT += core
|
||||
QT -= gui widgets
|
||||
TARGET = luaenginec
|
||||
CONFIG += c++11
|
||||
|
||||
static: DEFINES += LUAENGINE_STATIC
|
||||
|
||||
CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaenginecore/debug -lLuaEngine
|
||||
CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaenginecore/release -lLuaEngine
|
||||
unix: LIBS += -L$$OUT_PWD/../luaenginecore -lLuaEngine
|
||||
|
||||
INCLUDEPATH += \
|
||||
../luaenginecore/lua \
|
||||
../luaenginecore/luaengine \
|
||||
|
||||
SOURCES += \
|
||||
main.cpp
|
100
src/luaenginec/main.cpp
Normal file
100
src/luaenginec/main.cpp
Normal file
|
@ -0,0 +1,100 @@
|
|||
/*****************************************************************************
|
||||
* luaEngine Lua Engine for Qt
|
||||
* Copyright (C) 2018-2019 Syping
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "LuaEngine.h"
|
||||
#include <QCommandLineParser>
|
||||
#include <QCommandLineOption>
|
||||
#include <QCoreApplication>
|
||||
#include <QTextStream>
|
||||
#include <QSaveFile>
|
||||
#include <QFile>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
a.setApplicationName("luaenginec");
|
||||
a.setApplicationVersion("0.1");
|
||||
|
||||
QCommandLineParser parser;
|
||||
|
||||
QCommandLineOption pLuaEngineOption(QStringList() << "le" << "luaengine", "Location of portable Lua Engine executor.", "luaengine");
|
||||
parser.addOption(pLuaEngineOption);
|
||||
|
||||
parser.addPositionalArgument("source", "Source file to build.");
|
||||
parser.addPositionalArgument("output", "Output file.");
|
||||
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
|
||||
parser.process(a);
|
||||
|
||||
const QStringList args = parser.positionalArguments();
|
||||
|
||||
QFile luaScript(args.at(0));
|
||||
|
||||
LuaEngine luaEngine;
|
||||
if (!luaEngine.loadLuaScript(&luaScript)) {
|
||||
QTextStream(stderr) << "Failed to load \"" << args.at(0) << "\"." << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
QSaveFile outputFile(args.at(1));
|
||||
if (!outputFile.open(QIODevice::WriteOnly)) {
|
||||
QTextStream(stderr) << "Failed to open \"" << args.at(1) << "\"." << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
QString pLuaEngine = parser.value(pLuaEngineOption);
|
||||
if (!pLuaEngine.isEmpty()) {
|
||||
QFile portableLuaEngine(pLuaEngine);
|
||||
if (!portableLuaEngine.open(QIODevice::ReadOnly)) {
|
||||
outputFile.cancelWriting();
|
||||
outputFile.commit();
|
||||
QTextStream(stderr) << "Failed to open \"" << pLuaEngine << "\"." << endl;
|
||||
return 1;
|
||||
}
|
||||
outputFile.write(portableLuaEngine.readAll());
|
||||
}
|
||||
|
||||
const QByteArray luaDump = luaEngine.dumpLuaScript();
|
||||
int dumpSize = luaDump.size();
|
||||
outputFile.write(luaDump);
|
||||
|
||||
if (!pLuaEngine.isEmpty()) {
|
||||
QByteArray lengthArray = QByteArray::number(dumpSize, 16);
|
||||
if (lengthArray.size() > 8) {
|
||||
outputFile.cancelWriting();
|
||||
outputFile.commit();
|
||||
QTextStream(stderr) << "Lua Engine script is too large." << endl;
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
while (lengthArray.size() != 8) {
|
||||
lengthArray.insert(0, "0");
|
||||
}
|
||||
}
|
||||
outputFile.write(QByteArray::fromHex(lengthArray));
|
||||
outputFile.write("\xb4\x00", 2);
|
||||
}
|
||||
|
||||
if (!outputFile.commit()) {
|
||||
QTextStream(stderr) << "Failed to write \"" << args.at(1) << "\"." << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue