Skip to content

Commit

Permalink
[export] Fix and improve LUA support
Browse files Browse the repository at this point in the history
  • Loading branch information
hgy29 committed Dec 7, 2016
1 parent 1ce4fb7 commit 70234ae
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions gdrexport/ExportLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
#include "ExportCommon.h"
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}

static ExportXml *currentXml=NULL;
static bool inited=false;

static int getProperty(lua_State* L)
{
Expand Down Expand Up @@ -55,6 +57,7 @@ static int bindAll(lua_State* L)
void ExportLUA_Init(ExportContext *ctx)
{
ctx->L = luaL_newstate();
luaL_openlibs(ctx->L);
lua_pushcfunction(ctx->L, bindAll);
lua_call(ctx->L, 0, 0);
}
Expand All @@ -67,6 +70,11 @@ void ExportLUA_Cleanup(ExportContext *ctx)

bool ExportLUA_CallFile(ExportContext *ctx,ExportXml *xml,const char *fn)
{
if (!inited)
{
inited=true;
ExportLUA_CallFile(ctx,xml,"Tools/export_init.lua");
}
if (luaL_loadfile(ctx->L,fn))
{
const char *err=lua_tostring(ctx->L, -1);
Expand All @@ -89,6 +97,11 @@ bool ExportLUA_CallFile(ExportContext *ctx,ExportXml *xml,const char *fn)

bool ExportLUA_CallCode(ExportContext *ctx,ExportXml *xml,const char *code)
{
if (!inited)
{
inited=true;
ExportLUA_CallFile(ctx,xml,"Tools/export_init.lua");
}
if (luaL_loadstring(ctx->L,code))
{
const char *err=lua_tostring(ctx->L, -1);
Expand Down
3 changes: 3 additions & 0 deletions gdrexport/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "ExportCommon.h"
#include "ExportBuiltin.h"
#include "ExportXml.h"
#include "ExportLua.h"

static bool readProjectFile(const QString& fileName,
ProjectProperties &properties,
Expand Down Expand Up @@ -474,10 +475,12 @@ int main(int argc, char *argv[])
replaceList2 << qMakePair(assetsPrefix + encryptionZero, assetsPrefixRnd + assetsKey);
ctx.replaceList << replaceList2;

ExportLUA_Init(&ctx);
if (ctx.deviceFamily==e_Xml)
ExportXml::exportXml(xmlExports[ctx.platform],false,&ctx);
else
ExportBuiltin::doExport(&ctx);
ExportLUA_Cleanup(&ctx);

return 0;
}
3 changes: 3 additions & 0 deletions ui/Tools/export_init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--[[
Called before the first LUA tag of a .gplugin or .gexport file
]]

0 comments on commit 70234ae

Please sign in to comment.