Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using cjson in embedded Lua in C++

Tags:

c++

lua

I have a C++ program that creates a lua_State and run custom Lua script. If I would like to have the lua_State pre-load cjson instead of requiring calling "require" in the Lua code, can I know whether it is possible and how can I do that?

like image 874
keelar Avatar asked Feb 17 '26 06:02

keelar


1 Answers

Yes, it's possible. Use luaL_requiref for that. Use this or this function as argument. You'll need to link the cjson code to your executable, and the compiler would probably appreciate a function declaration for the luaopen_* functions. If you use Lua 5.1 (which doesn't have luaL_requiref yet) you can use or steal from Compat-5.3.

like image 155
siffiejoe Avatar answered Feb 18 '26 19:02

siffiejoe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!