#pragma once

#include <client.h>
#include <wasm-rt.h>

namespace fugg {
    namespace wasm
    {
        class Table {
            wasm_rt_table_t** table;

        public: 
            explicit Table(wasm_rt_table_t** table) : table(table) { }

            wasm_rt_elem_t* element(uintptr_t address) const {
                return &(*table)->data[address];       
            }
        };   

        static auto kTable = Table { &Z_clientZ_table };
    }


    template<typename T>
    static T function_ref(uintptr_t address) {
        const auto& element = wasm::kTable.element(address);

        return reinterpret_cast<T>(element->func);
    }
}