将Java翻译成Lua

时间:2015-07-05 05:37:28

标签: java lua

我正在制作游戏,但我无法将以下Java代码翻译成Lua:

<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use App\Models\StaticPage;

class StaticPageTableSeeder extends Seeder
{

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run() {

        Model::unguard();

        DB::table('static_pages')->truncate();

        StaticPage::create([

            'slug'           => 'car-loans';
            'titles_en'      => '<h1>Car Loan</h1><h2>What you need to get one</h2>';
            'featured_image' => 'article_uploads/text-page-bgr.jpeg';
            'content_en'     => 

<<<EOT

                        <p class="highlight">The vast majority of cars aren't bought by consumers at all; they're purchased by banks. Very few buyers pay cash outright. The rest either borrow or lease a car from the real owner: a bank, an automaker's finance arm or a credit union. Shopping for a loan isn't as fun as shopping for the car itself, but it's not as difficult as securing a mortgage, either. We recommend that you shop around for a loan before you go to a dealership. Before you can shop for a loan, though, you'll need to determine a few things.</p>
                        <h3>Determine What Car You Can Afford</h3>
                        <p>It might seem difficult to make this determination before test-driving a bunch of cars, but it's best to steer clear of the sales floor until you've done your research. <q class="hidden-sm hidden-xs">The vast majority of cars aren't bought by consumers at all; they're purchased by banks.</q> Affordability isn't just about the car's price; it's about the cost of financing, insuring, fueling and maintaining it. If you're like most shoppers, you have an idea of the type you want and how much car you're likely to get for the amount you've got to spend. Be sure to include one-time charges like taxes, title and license fees, and the destination charge when you're figuring out how much you can spend, as well as factoring in continuing costs such as insurance and gas.</p>
                        <h3>Shop for Loans Before Going to the Dealership</h3>
                        <p>If you're buying a new car, the financing with the best interest rate might come from the automaker, available only through the dealer. Zero percent financing and other seemingly too-good-to-be-true offers come from so-called "captive" finance companies like GM's GMAC and Toyota Financial Services. Often they're not too good to be true (though the best terms are limited to specific models, loan periods and buyers with the best credit ratings). Dealers don't always have the best deals, though, and when they're not operating through a captive finance company they get a commission for setting up a loan with a bank you could go to directly.</p>
                        <figure class="__img-caption">
                            <img src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iNjAwIiBoZWlnaHQ9IjQwMCIgdmlld0JveD0iMCAwIDYwMCA0MDAiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPjwhLS0KU291cmNlIFVSTDogaG9sZGVyLmpzLzYwMHg0MDAvYXV0bwpDcmVhdGVkIHdpdGggSG9sZGVyLmpzIDIuNS4wLgpMZWFybiBtb3JlIGF0IGh0dHA6Ly9ob2xkZXJqcy5jb20KKGMpIDIwMTItMjAxNSBJdmFuIE1hbG9waW5za3kgLSBodHRwOi8vaW1za3kuY28KLS0+PGRlZnMvPjxyZWN0IHdpZHRoPSI2MDAiIGhlaWdodD0iNDAwIiBmaWxsPSIjRUVFRUVFIi8+PGc+PHRleHQgeD0iMjI1LjEzMjgxMjUiIHk9IjIwMCIgc3R5bGU9ImZpbGw6I0FBQUFBQTtmb250LXdlaWdodDpib2xkO2ZvbnQtZmFtaWx5OkFyaWFsLCBIZWx2ZXRpY2EsIE9wZW4gU2Fucywgc2Fucy1zZXJpZiwgbW9ub3NwYWNlO2ZvbnQtc2l6ZTozMHB0O2RvbWluYW50LWJhc2VsaW5lOmNlbnRyYWwiPjYwMHg0MDA8L3RleHQ+PC9nPjwvc3ZnPg==" data-src="holder.js/600x400/auto" alt="600x400" data-holder-rendered="true">
                            <figcaption class="__caption hidden-sm hidden-xs">
                                Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut...
                            </figcaption>
                        </figure>
                        <p>After you've negotiated the car's purchase price, the only way to know if the deal you're presented with is a good one is for you to have shopped around beforehand. You may not be able to shop rates from the captive lenders before actually buying a car, but you can find out what kind of rates are available at banks and credit unions.</p>
                        <p>To know what kind of rate to expect, and to head off any obstacles you may encounter, you'll need to know your credit rating. Any lender will look it up as soon as you sit down with them to negotiate a loan. The rating takes into account how long you've had credit, how diligently you pay bills, how much of your available credit you've used, and your mix of revolving credit — such as credit cards — and more desirable debt, like a mortgage and previous car loans.</p>

EOT;

        ]);


    }
}

我如何在Lua中解决这个问题? 我尝试过以下方法:

pat = new ArrayList<Integer>();

random = new Random();

这是对的吗? 我的启动功能看起来像这样

pat = {}

random = math.random()

这是一个错误的启动方式吗?任何建议?

1 个答案:

答案 0 :(得分:0)

  

这是对的吗?

不完全。

  

随机随机=新的随机();

创建一个新的随机数 generator 。然后,您可以调用nextInt(int n)nextDouble()等方法来实际生成随机数。

在Lua中,有一个全局随机数生成器。调用math.random不会创建生成器,它使用该全局生成器生成数字。

  

pat = {}

这会创建一个表,可以用作双精度列表。如果你需要它们像int一样,并且你没有使用Lua 5.3+,你需要小心自己截断小数部分(例如math.floor