Posts: 783
Threads: 12
Joined: Jan 2014
Thanks: 2
Given 73 thank(s) in 61 post(s)
I'm just going through the cPluginManager::Call* methods to add locks and it seems to me that it would be far easier to autogenerate the methods from a list of Hooks. However that is somewhat beyond to c++ preprocessor. At the moment we have no dependent programs capable of generating the code and it seems slightly over the top to write a program in c++ to generate these methods. So how do you feel about adding a perl or python script to generate the methods?
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
I"m not an expert but we could maybe use Lua since that is what MCServer uses as scripting language?
Posts: 783
Threads: 12
Joined: Jan 2014
Thanks: 2
Given 73 thank(s) in 61 post(s)
Good point, I'll use that.
Posts: 783
Threads: 12
Joined: Jan 2014
Thanks: 2
Given 73 thank(s) in 61 post(s)
We have lua in the repository and you can invoke msbuild from the command line so i'll just write a batch script that will compile lua, generate the hooks and generate the buindings. You just then call the script whenever you currently run tolua++.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
01-12-2014, 03:03 AM
(This post was last modified: 01-12-2014, 03:09 AM by xoft.)
A silly idea: could we bend tolua++ to actually execute a Lua script for us? Then we won't need to compile Lua at all - the tolua++ executable is already in the repository for Windows to use.
Because invoking msbuild means you need to execute it in a shell that has been VisualStudio-lized (typically from the start menu -> visual studio -> visual studio command prompt, then chdir to your folder, then execute script), it is rather difficult for newcomers.
Yup, it should be possible - tolua++ has the -L option that runs any Lua file before doing the tolua run, so it could be done.
Unfortunately it only supports one such file and we already use one for generating the bindings. So the code will have to be appended to that file, rather than in a separate file - or use a "dofile()" function.
Posts: 783
Threads: 12
Joined: Jan 2014
Thanks: 2
Given 73 thank(s) in 61 post(s)
01-12-2014, 04:16 AM
(This post was last modified: 01-12-2014, 04:34 AM by worktycho.)
So if lua is impractical as well is there any sensible way of doing code generation or am I going to have horrible macros or have bindings regenerate on completely irrelevant things so that they can generate something completely different or can you think of a practical way of generating code in visual studio that isn't T4 files.
How about we just commit a lua interpreter executable to the repository for windows. Its only windows that has the problem with autogenerated files so only windows needs the special handling.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
Lua is practical and the interpreter is already there in tolua++, you can use it - just append your code to $/src/Bindings/virtual_method_hooks.lua. Even better, this file is called when generating the Bindings.cpp, so it will regenerate the hooks code at the same time.
Posts: 783
Threads: 12
Joined: Jan 2014
Thanks: 2
Given 73 thank(s) in 61 post(s)
That will do for this but it does seem like a hack and will only work for hook processing without losing incremental compilation.