Keeping everything in a single lua bytecode chunk?

前端 未结 4 1522
梦毁少年i
梦毁少年i 2021-02-02 16:32

I\'ve embedded lua together with a bytecode chunk into a project written in C. Now when I extend my lua code base by adding .lua files, is there a way to keep this code in a sin

4条回答
  •  面向向阳花
    2021-02-02 17:21

    loadstring is what your looking for. It takes a string and loads if (after compiling it to byte code if necessary). It results in a function that can be executed to run the contained code afterwards.

    If you still need something more general, take a look at load which lets you specify a function to feed the chunks in.

    Both functions can process both Lua source code and compiled byte code.

提交回复
热议问题