Skip to content

Commit

Permalink
[lua] added API macros. looks to be pretty nifty!
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed Aug 28, 2023
1 parent 18afbc9 commit c3c0398
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ add_library(topaz STATIC
src/tz/io/image.hpp

# tz::lua
src/tz/lua/api.hpp
src/tz/lua/lua.hpp
src/tz/lua/state.cpp
src/tz/lua/state.hpp

Expand Down
21 changes: 21 additions & 0 deletions src/tz/lua/api.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef TZ_LUA_API_HPP
#define TZ_LUA_API_HPP
#include "tz/lua/state.hpp"
#include "tz/core/debug.hpp"

#define LUA_BEGIN(name) int luafn_##name(void* state){

#define LUA_END }
#define LUA_REGISTER(name) tz::lua::for_all_states([](tz::lua::state& s){s.assign_func(#name, luafn_##name);});

// example: define in a TU
//LUA_BEGIN(test_me_please)
// tz::report("test successful!");
// return 0;
//LUA_END

// usage: somewhere during runtime, invoke:
// LUA_REGISTER(test_me_please)
// which makes the function resident to all lua states on both the main thread and the job system worker threads.

#endif // TZ_LUA_API_HPP

0 comments on commit c3c0398

Please sign in to comment.