What are the recommended approaches for handling the integration of Lua scripts with PHP to ensure efficient and secure execution?

When integrating Lua scripts with PHP, it is important to ensure efficient and secure execution by using proper sanitization techniques to prevent code injection and by carefully handling the communication between the two languages to avoid potential vulnerabilities.

// Example PHP code snippet for integrating Lua scripts securely
$luaScript = $_POST['lua_script']; // Assuming Lua script is submitted via POST request

// Sanitize Lua script input
$luaScript = htmlspecialchars($luaScript);

// Create Lua interpreter object
$lua = new Lua();

// Execute the Lua script
$result = $lua->eval($luaScript);

// Output the result
echo $result;