Commit b3dba5f4 authored by Artur Grunau's avatar Artur Grunau
Browse files

Initial support for pipelines implemented in Lua

A new class, LuaPipeline, has been added to the scripting module. It
provides a way of interfacing with pipelines implemented in Lua.

For the time being only the most basic operations (i.e. init and deinit)
are supported, but work on making it possible to implement
fully-functional pipelines in Lua is underway.

References #1
parent d15ba3ca
......@@ -39,7 +39,7 @@ SWIG_LINK_LIBRARIES(vis campvis-core campvis-modules tgt ${CampvisGlobalExternal
ADD_EXECUTABLE(campvis-scripting ${CampvisScriptingSources} ${CampvisScriptingHeaders})
ADD_DEFINITIONS(${CampvisGlobalDefinitions} ${CampvisScriptingDefinitions})
INCLUDE_DIRECTORIES(${CampvisGlobalIncludeDirs})
TARGET_LINK_LIBRARIES(campvis-scripting campvis-core tgt ${CampvisGlobalExternalLibs})
TARGET_LINK_LIBRARIES(campvis-scripting campvis-core campvis-modules tgt ${CampvisGlobalExternalLibs})
# Copy Lua test scripts into the target directory
ADD_CUSTOM_COMMAND(
......
#include "luapipeline.h"
namespace campvis {
void callLuaFunc(lua_State* _luaState, int nargs, int nresults) {
if (lua_pcall(_luaState, nargs, nresults, 0) != LUA_OK) {
const char* errorMsg = lua_tostring(_luaState, -1);
if (errorMsg == nullptr)
std::cout << "(error object is not a string)" << std::endl;
else
std::cout << errorMsg << std::endl;
lua_pop(_luaState, 1);
}
}
LuaPipeline::LuaPipeline(lua_State* state, DataContainer* dc)
: AutoEvaluationPipeline(dc)
, _luaState(state)
{
lua_getglobal(state, "pipeline");
if (!lua_istable(state, -1))
printf("No valid Lua pipeline found (pipeline is %s)\n", lua_typename(state, lua_type(state, -1)));
lua_pop(state, 1);
}
void LuaPipeline::init() {
AutoEvaluationPipeline::init();
lua_getglobal(_luaState, "pipeline");
lua_getfield(_luaState, -1, "init");
lua_getglobal(_luaState, "pipeline");
callLuaFunc(_luaState, 1, 0);
// Pop the pipeline table
lua_pop(_luaState, 1);
}
void LuaPipeline::deinit() {
AutoEvaluationPipeline::deinit();
lua_getglobal(_luaState, "pipeline");
lua_getfield(_luaState, -1, "deinit");
lua_getglobal(_luaState, "pipeline");
callLuaFunc(_luaState, 1, 0);
// Pop the pipeline table
lua_pop(_luaState, 1);
}
}
#ifndef LUAPIPELINE_H__
#define LUAPIPELINE_H__
extern "C" {
#include "lua.h"
}
#include "core/pipeline/autoevaluationpipeline.h"
namespace campvis {
class LuaPipeline : public AutoEvaluationPipeline {
public:
LuaPipeline(lua_State* state, DataContainer* dc);
/// \see AbstractPipeline::getName()
virtual const std::string getName() const { return getId(); }
static const std::string getId() { return "LuaPipeline"; }
/// \see AutoEvaluationPipeline::init()
virtual void init();
/// \see AutoEvaluationPipeline::deinit()
virtual void deinit();
protected:
lua_State* _luaState;
};
}
#endif // LUAPIPELINE_H__
......@@ -6,12 +6,22 @@ require("vis")
print(campvis.StringProperty)
print(vis.MhdImageReader)
pipeline = {}
function pipeline:init()
print("I'm being inited!")
self.mir = vis.MhdImageReader()
end
function pipeline:deinit()
print("I'm being deinited!")
end
local nt = campvis.StringProperty("a", "b", "c", campvis.AbstractProcessor_INVALID_RESULT)
print(nt:getValue())
nt:setValue("d")
print(nt:getValue())
local mir = vis.MhdImageReader()
local iv = campvis.ivec2(50, 10)
print(vis.first(iv))
......
......@@ -4,6 +4,13 @@ extern "C" {
#include "lauxlib.h"
}
#include "modules/pipelinefactory.h"
#include "luapipeline.h"
using namespace campvis;
int main()
{
lua_State* L = luaL_newstate();
......@@ -23,6 +30,16 @@ int main()
lua_pop(L, 1);
}
PipelineFactory& pipelineFactory = PipelineFactory::getRef();
pipelineFactory.registerPipeline<LuaPipeline>([L] (DataContainer* dc) -> AbstractPipeline* {
return new LuaPipeline(L, dc);
});
DataContainer* dc = new DataContainer("Test Data Container");
AbstractPipeline* p = pipelineFactory.createPipeline("LuaPipeline", dc);
p->init();
p->deinit();
printf("\nI am done with Lua in C++.\n");
lua_close(L);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment