This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // File: main.cpp | |
| #include "myclass.h" | |
| myclass my_class_instance; // global instance of myclass | |
| myclass* get_myclass() // Definition of get_myclass declared in myclass.h | |
| { | |
| return &my_class_instance; | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | -- File: main.lua | |
| myclass = mylua.get_myclass() -- Get the instance of myclass | |
| function show_text(text) -- Declare a function to print stuff | |
| print("lua function:"..text) | |
| end | |
| myclass:call_lua_function("show_text") -- Init c++ callback to a lua function | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // File: mylua.i | |
| %module mylua | |
| %{ | |
| #include "myclass.h" | |
| %} | |
| %include <std_string.i> | |
| %include <typemaps.i> | |
| namespace boost | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // Class that we are going to access from the Lua script | |
| class myclass | |
| { | |
| public: | |
| void init() | |
| { | |
| my_script = script_ptr(new script()); | |
| my_script->init(); | |
| my_script->load("main.lua"); | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // Helper class to call a function declared in a Lua script | |
| class callback | |
| { | |
| public: | |
| callback():r_obj(0), r_func(0), L(NULL), num_params(0), num_return(0) {} | |
| void init(script_ptr& s, const std::string& func, int n_params=0, int n_ret=0) | |
| { | |
| L = s->L; | |
| num_params = n_params; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // Helper class to load a Lua script | |
| class script | |
| { | |
| friend class callback; | |
| public: | |
| bool init() | |
| { | |
| // Initialize lua | |
| L = lua_open(); | |
| luaL_openlibs(L); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // File: myclass.h | |
| extern "C" { | |
| #include <lua.h> | |
| #include <lualib.h> | |
| #include <lauxlib.h> | |
| extern int luaopen_mylua(lua_State* L); | |
| } | |
| #include <iostream> | |
| #include <string> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #include <iostream> | |
| #include "engine.h" | |
| class console | |
| { | |
| public: | |
| void write_line(const std::string& text) | |
| { | |
| std::cout << text <<std::endl; | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // main.as | |
| void main() | |
| { | |
| console con; | |
| con.write_line("hola mundo!"); | |
| } | |
| // test.as | |
| void test() | |
| { | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #include <string> | |
| #include <boost/smart_ptr.hpp> | |
| #include <angelscript.h> | |
| class module; | |
| class engine; | |
| class callback | |
| { | |
| public: |