Commit ca380d49 authored by Vaastav Anand's avatar Vaastav Anand
Browse files

Add lua wrappers for operations on baggage

parent 9547e604
......@@ -54,6 +54,7 @@ find_package(Lua51 REQUIRED)
add_library(luaxtrace SHARED
src/luaxtrace.cpp
src/module.cpp
src/lua_baggage.cpp
)
target_include_directories(luaxtrace PRIVATE ${LUA_INCLUDE_DIR} /usr/local/include/xtrace)
......
#pragma once
#ifndef _LUA_BAGGAGE_H_
#define _LUA_BAGGAGE_H_
extern "C" {
#include <lauxlib.h>
#include <lua.h>
} //extern "C"
namespace lua_xtracer {
// All the baggage operations are on the serialized versions of Baggage
extern int SetBaggage(lua_State* L);
extern int JoinBaggage(lua_State* L);
extern int BranchBaggage(lua_State* L);
extern int DeleteBaggage(lua_State* L);
} //end namespace lua_xtracer
#endif
#include "baggage.h"
#include "lua_baggage.h"
#include <string>
#include <iostream>
namespace lua_xtracer {
Baggage getBaggageFromLua(lua_State* L) {
std::string baggage_string = "";
int n = lua_gettop(L);
if (n == 0) {
std::cout << "Baggage not provided as an argument" << std::endl;
} else {
baggage_string = lua_tostring(L, 1);
}
Baggage b = Baggage::deserialize(baggage_string);
return b;
}
int SetBaggage(lua_State* L) {
Baggage b = getBaggageFromLua(L);
SET_CURRENT_BAGGAGE(b);
return 0;
}
int JoinBaggage(lua_State* L) {
Baggage b = getBaggageFromLua(L);
JOIN_CURRENT_BAGGAGE(b);
return 0;
}
int DeleteBaggage(lua_State* L) {
DELETE_CURRENT_BAGGAGE();
return 0;
}
int BranchBaggage(lua_State* L) {
Baggage b = BRANCH_CURRENT_BAGGAGE();
std::string serialized_baggage = b.str();
lua_pushstring(L, serialized_baggage.c_str());
return 1;
}
} //end namespace lua_xtracer
#include "luaxtrace.h"
#include "lua_baggage.h"
#include <iostream>
extern "C" {
......@@ -31,6 +32,10 @@ extern "C" int luaopen_luaxtrace(lua_State* L) {
{"IsTracing", lua_xtracer::IsTracing},
{"StartLuaTrace", lua_xtracer::StartLuaTrace},
{"LogXTrace", lua_xtracer::LogLocal},
{"SetBaggage", lua_xtracer::SetBaggage},
{"JoinBaggage", lua_xtracer::JoinBaggage},
{"DeleteBaggage", lua_xtracer::DeleteBaggage},
{"BranchBaggage", lua_xtracer::BranchBaggage},
{nullptr, nullptr}
};
std::cout << "Registering functions" << std::endl;
......
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