Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 4 and Version 5 of code/Scripting


Ignore:
Timestamp:
May 10, 2009, 9:50:40 PM (16 years ago)
Author:
dafrick
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/Scripting

    v4 v5  
    4242
    4343We 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
     46With those two steps Lua will be able to access the functions and classes you want to alter with the script.
    5747
    5848=== Mark the function and classes ===
     
    7868} // tolua_export
    7969}}}
    80 As you see toLua++ parses only the party in the file where there is a ''tolua_exprt'' 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.
     70As 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.
    8171
    8272It 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.
     
    8979''orxonox'' is the namespace, ''Script'' is the class and ''getInstance()'' and ''luaPrint()'' are the functions. ''scr'' is an instance of the Script-class.
    9080
    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 ===
     82Open the CMakeLists.txt file in the src/orxonox folder and add the path to your header file to the GENERATE_TOLUA_BINDINGS command.