简体   繁体   English

将Lua代码与API中的C代码混合使用

[英]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. 我正在为我的应用程序创建一个Lua API,以实现快速,数据驱动的设计和可修改性。 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. 该库应该在每个子模块的文件中实现(以及用于顶级核心功能的文件),并且一些功能也可以在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. 好吧,一种方法是将组件视为单独的库,然后将它们拉入Lua中的core对象。 Implement audio , network etc. as standalone components, and make core along the lines of audionetwork等作为独立组件实现,并使其成为core

-- 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. 一般来说,混合C和Lua实现一个模块应该很容易google。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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