0

I am reading this lua thread tutorial and my lua code may be accessed by other threads at anytime and all I wan to do is to protect the luaState from corrupting.

I just searched luajit's source but found there is no lua_lock/lua_unlock in place. So is that possible to add such lock/unlock to luajit? If yes, how to?

BTW, I am using Visual C++ on Windows

Mickey Shine
  • 12,187
  • 25
  • 96
  • 148
  • Not sure why this was downvoted. Perfectly reasonable question. The implication of the linked tutorial is that Lua implementations provide lua_lock/lua_unlock hooks as empty macros, and that you can replace them in a platform-dependent way if you wish. A quick grep through the source of lua5.3 and luajit2.0.4 (the versions I happen to have) shows that this is true for vanilla Lua but not for LuaJIT. – cooperised Jul 02 '18 at 08:00

2 Answers2

2

LuaJIT doesn't provide support for lua_lock/unlock. You will have to manually control access to the lua_State yourself.

Colonel Thirty Two
  • 23,953
  • 8
  • 45
  • 85
0

As clearly stated in that tutorial, there are no "lua_lock/lua_unlock" functions, either in the regular Lua or LuaJIT distro. You are supposed to write them. The tutorial provides examples for Windows, but if you're not using Windows threading, you have to write them yourself.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • Yes I know the tutorial has clear statements but I got my app crashed after I made the modification according to that tutorial(I am using lua 5.1 for test). – Mickey Shine May 20 '13 at 00:03
  • the callstack:> ntdll.dll!77bd224d() Unknown [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] ntdll.dll!77bd215c() Unknown Test.exe!_LuaLock() C Test.exe!_lua_atpanic() C Test.exe!_luaL_newstate() C kernel32.dll!7753ed6c() Unknown ntdll.dll!77c0377b() Unknown ntdll.dll!77c0374e() Unknown – Mickey Shine May 20 '13 at 00:05