Add a way to call luaL_loadstring .#109
Add a way to call luaL_loadstring .#109Zardoz89 wants to merge 4 commits intojeremyong:masterfrom Zardoz89:develop
Conversation
include/selene/State.h
Outdated
|
Thanks for the PR! This code is very similar to the code for loading from a file. Can any of the code be consolidated or factored out in a more generic way? |
|
Comes to my head a few methods :
The second case is the most flexible, and Load(filename) could become a simple tiny wrapper around LoadFrom that opens the file, pass the ostream to LoadFrom, and closes it. Sadly my C++ template skills are actually poor. I could try, but actually I'm trying more to get working a lua scripting system integrated on Trillek. |
|
I was thinking something with less machinery. Really the only difference is a call to loadFile vs loadString, and the rest could be lifted to a separate common helper function (unless I missed something) |
|
It could work better. I think that over-engineered the problem. |
LoadString looks that collides with some Windows API macro, so using LoadStr instead of LoadString
Shared code moved to a private inlined method : PostLoad Also, explicit check of pointers against nullptr
include/selene/State.h
Outdated
There was a problem hiding this comment.
This can just be return PostLoad(status)
|
I think removing all the uses of |
|
I'd really like to see this supported, I'm currently working on a project where lua code arrives over the network and no files ever touch the disk. |
Why ? Well, on some case, would be interesting to handle strings on memory instead loading/saving directly to HDD, in special when there is some kind of filesystem abstraction, or Selene it's being used inside a script editor.
LoadString looks that collides with some Windows API macro, so using LoadStr
instead of LoadString.