简体   繁体   中英

Mixing Lua code with C code in an API

I'm creating a Lua API for my application for quick, data-driven design and moddability. It follows this module/submodule hierarchy:

core
 -> audio
 -> network
 -> video
 -> etc.

The library should be implemented in a file per submodule (as well as a file for the top-level core functions), and some functions may also be implemented in C.

What's the best way to organize this?

Well, one way would be to treat the components as separate libraries, and just pull them into core object in Lua. Implement audio , network etc. as standalone components, and make core along the lines of

-- core.lua

core = {
    audio = require "audio",
    network = require "network",
    ...
}
return core

This should work well enough and that "module reexport pattern" is something I've seen in many languages, so I guess it should work alright.

Mixing C and Lua implementation for one module is something that should be easily google'able, in general.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM