I am not sure whether it is suitable to ask this question here, but I will try to explain my question as clearly as possible.
I have a machine to control. Basic operation functions (e.g. move, open doors, wait for commands, etc.), interfaces, etc are all writen in C++, and we need to write some service scripts in lua. The pseudo codes of service scripts are like:
* define the service name and give some description
* declare the task address
* declare the input and output class name
* list the input plugin files
* define a "run" function
-- publish the machine state
-- initialize the machine
-- wait for commands
-- call the "service" function
-- wait for stop command
* define a "service" function
-- set the service state to be true
-- move the car to destination
-- open the door for a while
-- close the door
* after the service is finished, send a "finish" flag to the center handler.
In this pseudo code, we have 2 functions, and lines started with "--" are usually basic operation functions written in C++ or functions defined in other lua plugin files.
I have written very simple C++ code and Lua script before and connected them. But they are just like pass a table of numbers from C++ to lua, use functions in lua to calculate the sum/factorial/sqaure... and then pass the result back to C++ and print out. In such exercises, I just used functions such as lua_State *L; L = luaL_newstate(); luaL_openlibs(); luaL_loadfile(); lua_pcall(); lua_tostring(); lua_tonumber(); ......
But now I need to handle such a complicated lua script and C++ code system. I think simply doing what I used to do is not enough....I was wondering whether there is a specific way to parse the lua script, get value of each component (task address, function, etc..) and save them in C++ code, then probably it will be easier for me to connect the extracted component to existing C++ functions....
Or is this possible: just return everything (including values, functions, etc...) from lua in the form of table, then I write a C++ code to read the table and save the values, and then I connect the extracted items to existing C++ functions....
I am not sure whether I make my question clearly...I am newbie in Lua and I think there is a large deal of greatness of Lua that I haven't found..I know people say that Lua is a light and fast language and I want to make the most of it. If you understand my question and have better ideas to solve my problem, I will be more than happy to learn!