Changes between Version 4 and Version 5 of code/Scripting
- Timestamp:
- May 10, 2009, 9:50:40 PM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
code/Scripting
v4 v5 42 42 43 43 We use toLua++ for the transition from Orxonox to Lua. To use Lua for scripting there are three steps you have to do: 44 1. Update the tolua.pkg package file 45 2. Mark the functions and classes you want to make accessible to Lua 46 3. Auto-generate tolua_bind.h and tolua_bind.cc file 47 With those three steps Lua will be able to access the functions and classes you want to alter with the script. 48 49 === Update the package file === 50 !ToLua++ has a package file which we call ''tolua.pkg''. This file is used by toLua++ to generate the necessary C/C++ files. There are many things one can write in this package file. However we need only to include our own .h files here. The following line in the package file includes the .h file of the class ''Script'': 51 {{{ 52 ... 53 $cfile "Script.h" 54 ... 55 }}} 56 This is used to make the [wiki:Scripting#Levelfiles above] possible. 44 1. Mark the functions and classes you want to make accessible to Lua 45 3. Update the CMakeLists.txt file 46 With those two steps Lua will be able to access the functions and classes you want to alter with the script. 57 47 58 48 === Mark the function and classes === … … 78 68 } // tolua_export 79 69 }}} 80 As you see toLua++ parses only the party in the file where there is a ''tolua_exp rt'' commentary and between ''tolua_begin'' and ''tolua_end'' commentaries. Like this we can specify exactly which functions should be accessible by Lua. You may want to only have Lua to fiddle with the public functions or you have a special private function just for Lua.70 As you see toLua++ parses only the party in the file where there is a ''tolua_export'' commentary and between ''tolua_begin'' and ''tolua_end'' commentaries. Like this we can specify exactly which functions should be accessible by Lua. You may want to only have Lua to fiddle with the public functions or you have a special private function just for Lua. 81 71 82 72 It is however important that you export namespaces and classes and not just the functions. Otherwise toLua++ would generate .h and .cc files which are not in the namespace so they cannot call the specified functions. … … 89 79 ''orxonox'' is the namespace, ''Script'' is the class and ''getInstance()'' and ''luaPrint()'' are the functions. ''scr'' is an instance of the Script-class. 90 80 91 === Auto generate .h and .cc files === 92 For this you will need tolua++ installed on your system. It can be downloaded [http://www.codenix.com/~tolua/#download here]. The following command will generate the necessary files to compile Orxonox after changes on the package file: 93 {{{ 94 tolua++ -n orxonox -H tolua_bind.h -o tolua_bind.cc tolua.pkg 95 }}} 96 It is necessary to exactly write this. Otherwise you will break the tolua_bind.h and .cc files and Orxonox will no longer compile. 81 === Update the CMakeLists.txt file === 82 Open the CMakeLists.txt file in the src/orxonox folder and add the path to your header file to the GENERATE_TOLUA_BINDINGS command.