Haskell: Converting a .lua table to Haskell workable types
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm a beginner trying to practice coding haskell by translating some simple repo from different languages to Haskell.
Many simple games use .lua to store character/ability data.
What I want is to take that .lua table and convert it into haskell workable types.
This is what the .lua file looks like
local Data =
{
["Weapons"] = {
["AB"] = {
Name = "AB",
Cost = {
Spells = 65000,
BCost = 15000,
MCost = 150,
sh = 35,
Time = 24,
Parts = {
{ Name = "Top",Type = "Item",Count = 1,},},
},
Resist = 0.85,
Class = "Shield",
Attack = {
Damage = {
["First"] = 5,
["Second"] = 5,
["Third"] = 40,},
Chance = 0.2,
X = 2,
},
},
["PG"] = {
...
...
...
}
return Data
When woking with Aeson, there's this simple function decode
which you can use as decode someJSON :: Maybe Object
and get the entirety of JSON file content put in default Aeson datatypes which you can work on with library functions. I haven't been able to find something similar for .lua
.
parsing haskell lua-table
add a comment |
I'm a beginner trying to practice coding haskell by translating some simple repo from different languages to Haskell.
Many simple games use .lua to store character/ability data.
What I want is to take that .lua table and convert it into haskell workable types.
This is what the .lua file looks like
local Data =
{
["Weapons"] = {
["AB"] = {
Name = "AB",
Cost = {
Spells = 65000,
BCost = 15000,
MCost = 150,
sh = 35,
Time = 24,
Parts = {
{ Name = "Top",Type = "Item",Count = 1,},},
},
Resist = 0.85,
Class = "Shield",
Attack = {
Damage = {
["First"] = 5,
["Second"] = 5,
["Third"] = 40,},
Chance = 0.2,
X = 2,
},
},
["PG"] = {
...
...
...
}
return Data
When woking with Aeson, there's this simple function decode
which you can use as decode someJSON :: Maybe Object
and get the entirety of JSON file content put in default Aeson datatypes which you can work on with library functions. I haven't been able to find something similar for .lua
.
parsing haskell lua-table
You may check hslua-aeson package. It seems to have instances to push and receive Aeson's Value type to and from the Lua stack.
– Redu
Nov 24 '18 at 17:42
@Redu From its README.md it seems like the package does JSON to Lua. Is converting Lua to JSON possible with that package?
– atis
Nov 24 '18 at 19:59
@Redu This is what I triedmain = do openlibs dofile "src/configfile.lua" wData <- getglobal "Data" *> peek (-1) liftIO $ print (wData :: Value)
after removinglocal
from the.lua
file.
– atis
Nov 24 '18 at 20:12
Sorry.. i have no experience with Lua - Haskell workflow at all. It was just an idea. Have you tried going through the code?
– Redu
Nov 24 '18 at 20:39
1
No worries! The code you linked does seem to convert Lua table values to Haskell inPeekable
instance. It might just work! I'll just need to work out how it operates.
– atis
Nov 25 '18 at 7:19
add a comment |
I'm a beginner trying to practice coding haskell by translating some simple repo from different languages to Haskell.
Many simple games use .lua to store character/ability data.
What I want is to take that .lua table and convert it into haskell workable types.
This is what the .lua file looks like
local Data =
{
["Weapons"] = {
["AB"] = {
Name = "AB",
Cost = {
Spells = 65000,
BCost = 15000,
MCost = 150,
sh = 35,
Time = 24,
Parts = {
{ Name = "Top",Type = "Item",Count = 1,},},
},
Resist = 0.85,
Class = "Shield",
Attack = {
Damage = {
["First"] = 5,
["Second"] = 5,
["Third"] = 40,},
Chance = 0.2,
X = 2,
},
},
["PG"] = {
...
...
...
}
return Data
When woking with Aeson, there's this simple function decode
which you can use as decode someJSON :: Maybe Object
and get the entirety of JSON file content put in default Aeson datatypes which you can work on with library functions. I haven't been able to find something similar for .lua
.
parsing haskell lua-table
I'm a beginner trying to practice coding haskell by translating some simple repo from different languages to Haskell.
Many simple games use .lua to store character/ability data.
What I want is to take that .lua table and convert it into haskell workable types.
This is what the .lua file looks like
local Data =
{
["Weapons"] = {
["AB"] = {
Name = "AB",
Cost = {
Spells = 65000,
BCost = 15000,
MCost = 150,
sh = 35,
Time = 24,
Parts = {
{ Name = "Top",Type = "Item",Count = 1,},},
},
Resist = 0.85,
Class = "Shield",
Attack = {
Damage = {
["First"] = 5,
["Second"] = 5,
["Third"] = 40,},
Chance = 0.2,
X = 2,
},
},
["PG"] = {
...
...
...
}
return Data
When woking with Aeson, there's this simple function decode
which you can use as decode someJSON :: Maybe Object
and get the entirety of JSON file content put in default Aeson datatypes which you can work on with library functions. I haven't been able to find something similar for .lua
.
parsing haskell lua-table
parsing haskell lua-table
asked Nov 24 '18 at 17:21
atisatis
388213
388213
You may check hslua-aeson package. It seems to have instances to push and receive Aeson's Value type to and from the Lua stack.
– Redu
Nov 24 '18 at 17:42
@Redu From its README.md it seems like the package does JSON to Lua. Is converting Lua to JSON possible with that package?
– atis
Nov 24 '18 at 19:59
@Redu This is what I triedmain = do openlibs dofile "src/configfile.lua" wData <- getglobal "Data" *> peek (-1) liftIO $ print (wData :: Value)
after removinglocal
from the.lua
file.
– atis
Nov 24 '18 at 20:12
Sorry.. i have no experience with Lua - Haskell workflow at all. It was just an idea. Have you tried going through the code?
– Redu
Nov 24 '18 at 20:39
1
No worries! The code you linked does seem to convert Lua table values to Haskell inPeekable
instance. It might just work! I'll just need to work out how it operates.
– atis
Nov 25 '18 at 7:19
add a comment |
You may check hslua-aeson package. It seems to have instances to push and receive Aeson's Value type to and from the Lua stack.
– Redu
Nov 24 '18 at 17:42
@Redu From its README.md it seems like the package does JSON to Lua. Is converting Lua to JSON possible with that package?
– atis
Nov 24 '18 at 19:59
@Redu This is what I triedmain = do openlibs dofile "src/configfile.lua" wData <- getglobal "Data" *> peek (-1) liftIO $ print (wData :: Value)
after removinglocal
from the.lua
file.
– atis
Nov 24 '18 at 20:12
Sorry.. i have no experience with Lua - Haskell workflow at all. It was just an idea. Have you tried going through the code?
– Redu
Nov 24 '18 at 20:39
1
No worries! The code you linked does seem to convert Lua table values to Haskell inPeekable
instance. It might just work! I'll just need to work out how it operates.
– atis
Nov 25 '18 at 7:19
You may check hslua-aeson package. It seems to have instances to push and receive Aeson's Value type to and from the Lua stack.
– Redu
Nov 24 '18 at 17:42
You may check hslua-aeson package. It seems to have instances to push and receive Aeson's Value type to and from the Lua stack.
– Redu
Nov 24 '18 at 17:42
@Redu From its README.md it seems like the package does JSON to Lua. Is converting Lua to JSON possible with that package?
– atis
Nov 24 '18 at 19:59
@Redu From its README.md it seems like the package does JSON to Lua. Is converting Lua to JSON possible with that package?
– atis
Nov 24 '18 at 19:59
@Redu This is what I tried
main = do openlibs dofile "src/configfile.lua" wData <- getglobal "Data" *> peek (-1) liftIO $ print (wData :: Value)
after removing local
from the .lua
file.– atis
Nov 24 '18 at 20:12
@Redu This is what I tried
main = do openlibs dofile "src/configfile.lua" wData <- getglobal "Data" *> peek (-1) liftIO $ print (wData :: Value)
after removing local
from the .lua
file.– atis
Nov 24 '18 at 20:12
Sorry.. i have no experience with Lua - Haskell workflow at all. It was just an idea. Have you tried going through the code?
– Redu
Nov 24 '18 at 20:39
Sorry.. i have no experience with Lua - Haskell workflow at all. It was just an idea. Have you tried going through the code?
– Redu
Nov 24 '18 at 20:39
1
1
No worries! The code you linked does seem to convert Lua table values to Haskell in
Peekable
instance. It might just work! I'll just need to work out how it operates.– atis
Nov 25 '18 at 7:19
No worries! The code you linked does seem to convert Lua table values to Haskell in
Peekable
instance. It might just work! I'll just need to work out how it operates.– atis
Nov 25 '18 at 7:19
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460618%2fhaskell-converting-a-lua-table-to-haskell-workable-types%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460618%2fhaskell-converting-a-lua-table-to-haskell-workable-types%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You may check hslua-aeson package. It seems to have instances to push and receive Aeson's Value type to and from the Lua stack.
– Redu
Nov 24 '18 at 17:42
@Redu From its README.md it seems like the package does JSON to Lua. Is converting Lua to JSON possible with that package?
– atis
Nov 24 '18 at 19:59
@Redu This is what I tried
main = do openlibs dofile "src/configfile.lua" wData <- getglobal "Data" *> peek (-1) liftIO $ print (wData :: Value)
after removinglocal
from the.lua
file.– atis
Nov 24 '18 at 20:12
Sorry.. i have no experience with Lua - Haskell workflow at all. It was just an idea. Have you tried going through the code?
– Redu
Nov 24 '18 at 20:39
1
No worries! The code you linked does seem to convert Lua table values to Haskell in
Peekable
instance. It might just work! I'll just need to work out how it operates.– atis
Nov 25 '18 at 7:19