feat(ext): add material api#106
Merged
Merged
Conversation
b807825 to
e995aae
Compare
cloudwu
reviewed
Jun 28, 2026
| { "shader_desc", lshader_desc }, | ||
| { "pipeline_desc", lpipeline_desc }, | ||
| { "submit_one", lsubmit_one }, | ||
| { "sprite", lperspective_quad_sprite }, |
Owner
There was a problem hiding this comment.
我感觉这里用类似 submit_one 这样的 api ,调用后再返回一个函数有点多此一举了。我觉得直接把 C function 以 lightuserdata 类似保存在这里就可以了。如果注册在 luaL_Reg l[] 中的话,只需要填 NULL 。
然后在 luaL_newlib(L, l)l 后面用 lua_pushlightuserdata(L, func); lua_setfield(L, -2, "submit_one"); 就可以放进去。当然也可以封装一个 set_func() 之类的函数。
不过我觉得还有个更好的方法:
因为这是一组 3 个 C 函数,我们并不确定后面再重构的话会不会修改。而且框架应该还需要在加载用户材质的时候需要再校验一次,所以我建议这里用
{ "cfuncs", NULL }, 模仿 luaL_Reg 定义一个类型:
struct cfuncs {
const char * name;
void *cfunc;
};
struct cfuncs cl[] = {
{ "shader", cshader_desc },
{ "pipeline", cpipeline_desc },
{ "submit", csubmit_one },
{ NULL, NULL },
// ...
luaL_newlib(L, l);
register_cfuncs(L, cl);
lua_setfield(L, -2, "cfuncs");其中, register_cfuncs() 抄 lauxlib.c 里的 luaL_newlib() 的实现稍微改一下就可以了。
在 lua side ,就可以用 extmat.cfuncs.submit 获得 csubmit_one() 。
Contributor
Author
There was a problem hiding this comment.
改了, 不过我觉得 cfuncs 不是很好听,就命名为 hooks 了
e995aae to
7831654
Compare
Owner
|
先合并。有问题再改。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
see #105