Skip to content

feat(ext): add material api#106

Merged
cloudwu merged 2 commits into
cloudwu:masterfrom
yuchanns:feat/materialapi
Jun 28, 2026
Merged

feat(ext): add material api#106
cloudwu merged 2 commits into
cloudwu:masterfrom
yuchanns:feat/materialapi

Conversation

@yuchanns

Copy link
Copy Markdown
Contributor

see #105

@yuchanns yuchanns force-pushed the feat/materialapi branch 3 times, most recently from b807825 to e995aae Compare June 28, 2026 12:59
Comment thread extlua/extlua_sample.c
{ "shader_desc", lshader_desc },
{ "pipeline_desc", lpipeline_desc },
{ "submit_one", lsubmit_one },
{ "sprite", lperspective_quad_sprite },

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我感觉这里用类似 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() 。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改了, 不过我觉得 cfuncs 不是很好听,就命名为 hooks 了

@cloudwu cloudwu merged commit 14a84ac into cloudwu:master Jun 28, 2026
5 checks passed
@cloudwu

cloudwu commented Jun 28, 2026

Copy link
Copy Markdown
Owner

先合并。有问题再改。

@yuchanns yuchanns deleted the feat/materialapi branch June 28, 2026 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants