• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ Calling variable(c++) from LUA

lexus21

Active Member
Joined
Dec 14, 2022
Messages
86
Reaction score
25
I use OTCv8 for my small project.
I have a module for otclientv8 written in C++. The module generates numbers every second into a variable.
I would like to have access to this variable from lua to use this variable in a lua script.
I'm wondering and slowly eating my mustache on this code(my experience in c++ is small).
How to read a variable (c++) in lua code?


in the file
luavaluecasts_client.cpp
I added:
C++:
int push_luavalue(const COM&Testdata)
{
     g_lua.createTable(0, 1);


     g_lua.pushInteger(10); // <--hardcoded value 10 - only for learnig only for learning purpose (imitates a variable)
     g_lua.setField("testDatavalue");


     return 1;
}

while in otclient, in modules, I created a sample module which should display the value 10. After opening the window.

Lua:
--window
function show()
   tWindow:show()
   if Testdata then
     print("this is testdata: ", Testdata.testDatavalue)
   end
   print("Hello")
   tButton:setOn(true)
end

What am I doing wrong that I don't have access to the variable from lua?
 
Last edited:
Back
Top