Return data from .lua file in PHP in array form

0

I need to access some data stored in a .lua file in PHP.

This is the content of the meu_arquivo.lua file:

tbl = {
    [22004] = {
        unidentifiedDisplayName = "Sapato",
        unidentifiedResourceName = "»÷µé",
        unidentifiedDescriptionName = {
            "Item não identificado. Pode ser identificado com uma [Lupa]."
        },
        identifiedDisplayName = "Botas Temporais DES",
        identifiedResourceName = "½Ã°£ÀǼÕÀçÁÖºÎÃ÷",
        identifiedDescriptionName = {
            "Botas incríveis que devem ter sido criadas há muito tempo, mas nunca foram usadas.",
            "^0000ffDEX +35.^000000",
            "Tipo: ^777777Calçado^000000",
            "Defesa: ^77777725^000000",
            "Peso: ^777777350^000000",
            "Nível necessário: ^77777799^000000",
            "Classes: ^777777Todas as classes^000000"
        },
        slotCount = 1,
        ClassNum = 0
    },
    [22005] = {
        unidentifiedDisplayName = "Sapato",
        unidentifiedResourceName = "»÷µé",
        unidentifiedDescriptionName = {
            "Item não identificado. Pode ser identificado com uma [Lupa]."
        },
        identifiedDisplayName = "Botas Temporais SOR",
        identifiedResourceName = "½Ã°£ÀÇÇà¿îºÎÃ÷",
        identifiedDescriptionName = {
            "Botas incríveis que devem ter sido criadas há muito tempo, mas nunca foram usadas.",
            "^0000ffLUK +35.^000000",
            "^0000ff+20 de Crítico.^000000",
            "Tipo: ^777777Calçado^000000",
            "Defesa: ^77777725^000000",
            "Peso: ^777777350^000000",
            "Nível necessário: ^77777799^000000",
            "Classes: ^777777Todas as classes^000000"
        },
        slotCount = 1,
        ClassNum = 0
    }
}

Example: I want to return the value of tbl > 22004 > unidentifiedDisplayName which would be Sapato as if it were a PHP array :

<?= $meu_arquivo['tbl']['22004']['unidentifiedDisplayName']; // mostra "Sapato" ?>

I do not know the syntax / language of this file to point my search more accurately. My only reference is that the file is read via LUA by the original application (Game).

Although it bears a resemblance to JSON , the json_decode function did not work for this file.

Any help is welcome!

    
asked by anonymous 02.03.2018 / 21:56

1 answer

1

One solution is to use the Lua extension for PHP: link

Here's an example using your .lua as input:

<?php
$lua = new Lua('./file.lua');
var_dump($lua->tbl[22004]['unidentifiedDisplayName']);

Produce the following output:

string(6) "Sapato"

I'll also leave here an example of installing the moon extension in PHP (of course depending on your production environment the instructions may vary but as I had to quickly have an environment to run the proposed solution, I thought it might be useful share)

FROM php:latest

RUN apt-get -y update \
 && apt-get -y install lua5.2 liblua5.2-0 liblua5.2-dev \
 && cp /usr/include/lua5.2/lua.h /usr/include/ \
 && ln -s /usr/include/lua*.*/ /usr/include/lua \
 && cp /usr/lib/x86_64-linux-gnu/liblua5.2.a /usr/lib/liblua.a \
 && cp /usr/lib/x86_64-linux-gnu/liblua5.2.so /usr/lib/liblua.so \
 && pecl install lua-2.0.2 \
 && docker-php-ext-enable lua
    
02.03.2018 / 23:46