Files
integration/luprex/cpp/core/invocation.hpp

88 lines
2.0 KiB
C++
Raw Normal View History

//////////////////////////////////////////////////////////////////////////
//
// DATAPACK
//
// Invocations contain a field 'datapack' which contains additional
// data for the invocation, packed up in a serialized format. Executing
// the invocation involves unpacking the datapack.
//
// The actual contents of the datapack depends on the type of invocation:
//
// KIND_INVALID:
//
// Nothing.
//
2024-02-07 15:59:17 -05:00
// KIND_ENGIO:
//
// First, a function name is read from the datapack. The function
// name must be a lua function inside class "engio". The function
// is called with arguments: actor, place, and then additional
// arguments of simple dynamic type read from the datapack.
//
// KIND_LUA:
//
// A block of lua source code, in plaintext.
//
// KIND_FLUSH_PRINTS:
//
// Line number in ascii.
//
// KIND_TICK:
//
// Nothing.
//
// KIND_LUA_SOURCE:
//
// Packaged lua sourcecode. See drvutil::package_lua_source.
//
//////////////////////////////////////////////////////////////////////////
#ifndef INVOCATION_HPP
#define INVOCATION_HPP
#include "wrap-string.hpp"
#include "wrap-map.hpp"
#include "wrap-deque.hpp"
#include "streambuffer.hpp"
class Invocation : public eng::opnew {
public:
enum Kind {
KIND_INVALID,
KIND_ENGIO,
2021-10-15 14:47:12 -04:00
KIND_LUA,
KIND_FLUSH_PRINTS,
2021-11-26 15:45:36 -05:00
KIND_TICK,
2021-12-15 14:18:19 -05:00
KIND_LUA_SOURCE,
};
private:
Kind kind_;
int64_t actor_;
int64_t place_;
eng::string datapack_;
public:
Invocation();
Invocation(Kind kind, int64_t actor, int64_t place, std::string_view datapack);
2021-11-16 12:20:11 -05:00
bool valid() const { return kind_ != KIND_INVALID; }
Kind kind() const { return kind_; }
int64_t actor() const { return actor_; }
int64_t place() const { return place_; }
const eng::string &datapack() const { return datapack_; }
void serialize(StreamBuffer *sb) const;
void deserialize(StreamBuffer *sb);
2021-11-11 16:23:11 -05:00
eng::string debug_string() const;
};
using UniqueInvocation = std::unique_ptr<Invocation>;
class InvocationQueue : public eng::deque<Invocation> {
};
#endif // INVOCATION_HPP