-
-
Notifications
You must be signed in to change notification settings - Fork 516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write a tutorial #36
Comments
I'm considering doing this. Setting up a test repo where we make like a little shooter game using C++ and Lua with Sol as the glue. ... But my time. I have so very little. If I get some free time, this will definitely be up there, though. |
Greetings. I used to use Sol but could not figure out how it works (was too stupid back then XD but the manual wasn't very good either) and thus quickly switched over to Selene, since on its main page it had a much better tutorial/how-to-manual. However now I'm currently using Selene and thinking about switching to Sol2 (because it supports LuaJit, being able to switch between luajit and lua5.3 for comparison is quite nice) and i think has more features. Personally, I'd suggest NOT writing a shooter game as a tutorial, at least for now. it would make things too complicated for people who just want to know how to use Sol2. Don't focus on giving a working example game, focus on explaining how to use Sol2 itself. I'd suggest taking a look at Selenes main page For tutorials, don't overcompliate things. Concentrate on single aspects with small dead-simple examples: Again, look at Selenes main page, i think that's the best way to show how a library gets used. EDIT : Just found your page http://sol2.readthedocs.org/en/latest/ |
Righty-o, I'll put the tutorial and a big Getting Started header in the readme when I do it. Unfortunately, school school school school school school school school school school school school. |
Haha, school is more important, i think everyone understands that. :) I just skimmed through your example code files. The only thing i couldn't figure out from your examples are : You only show how to register a class (that we can then new() in Lua), but what if we want to register an already existing C++ class instance in Lua? Objectclass someobject(); // how do i now register that class instance in lua? Of course i could think of a way (creating a Lua table for it, putting a pointer to the instance in the table as reference if i want to return a pointer of it from Lua to C++, and adding references to class methods) but i think a clearly written "how-to" would be good. Some additional things: lua["table"]["nestedtable"]["function"]();
lua.script("table.nestedtable.function()"); The different methods how to do it should get mentioned a bit more, to show users the different possibilities they have for writing their code. Also, i think it should be mentioned for new users that in the case of using sol::state lua; //creates empty lua state
lua.script_file("test.lua"); // loads all the contents of "test.lua" into the lua state
lua.script_file("config.lua"); // does NOT erase the content loaded from test.lua,
//but instead config.lua gets loaded in addition to the content already in the lua state I know that this is mostly common knowledge for many experienced users and it shouldn't be that high of a priority, but for beginners it's probably good to know (otherwise they start packing all their stuff in a single giant lua file ;-P ). Other than the sparse documentation/tutorial, i really, really like it so far, i'll switch my current project to Sol2 as soon as possible. Keep up the good work! |
Ah, right, I don't go over that, but the answer is simple for registering your own stuff:
This makes a copy/move, depending on what you ask for. If you want it to refer to something, whose memory you know won't die in C++,
You can also set They're all accessed the same way from lua, of course: no special reference/object syntax. Just use the |
As a buffer, I've updated the Readme to include a few pointers to places like examples and such. When I fix up the documentation I'll add some more in-your-face pointers to those as well. |
The first little bits of a tutorial were written in this commit: 92c388e Which shows up here: http://sol2.readthedocs.org/en/latest/tutorial/getting-started.html (the page isn't linked from the document root yet). |
Once this gets written up, we'll release 2.4... |
Current progress: http://sol2.readthedocs.org/en/latest/tutorial/tutorial-top.html I feel like there should be a "quick and dirty" page that reads more like Selene's readme, though... |
Things that still need to be done:
|
@Bulat-Ziganshin @Nava2 The hardcore documentation is done. Am going to update the readme and stuff soon. Let me know what you think. |
As a reasonable place to ask, who owns a pointer returned to sol? i.e. lua["my_func"] = []() -> my_type* {
return new my_type();
}; |
Nobody: you've just created a dangling pointer. To fix:
|
Should that explicitly be written down in the documentation somewhere? |
_0. it should mention first that
should be included. and that sol is a header-only library (that don't need compilation). that's enough - we know how to run compiler and use git _1. "set and get stuff" -> "set and get variables" _2. "Some classes that have stuff to make it easier to look at lua semantics / be safe." phrase was hard to understand. what about something like "Retrieving types of Lua objects" _3. in this code
either second line should be "myuserdata = 20" or it needs more descriptions _4. in this code
seems that it should be stdfx() and fx(1, 34.5, 3, "bark") _5. mistyped:
_6. this code:
should be
note "ghi" and 50 |
Here Thanks for all your help! |
_1. 2.8 -> 4.8:
_2. sol::bond -> bind? there are at least 2 occurences remained _3. here:
you don't defined ".tailwag" in Lua. section title says about metatables, but there is no code involving them _4. i suggest renaming section "more userdata + usertypes" to "exporting C++ classes to Lua". it's less generic but easier to grok _5. section titled "pointers" - seems that you mean that calls to my_func will create dangling pointers, not assignment itself? the text will be easier to grok if it will be stated explicitly _6. overall, there are several mentions of owning. i suggest to combine them all into the sungle section at the end of tutorial, since it's imho most advanced topic. this inlcudes sections "pointers", "userdata + usertypes (metatables)", and this code (that cannot be groked at the beginning of tutorial):
so overall tutorial sequence will be "simple types - tables - functions - binding C++ classes - object ownership" |
I guess I'll just name |
Okay, it's all fixed @Bulat-Ziganshin ! Thanks for all the help: I made sure to explicitly specify so does not take ownership of ANY pointers given to it, no matter how they're set / returned /cc @Nava2 . |
sorry, i'm not native speaker and my English is mostly limited to tech papers :) anyway, using the same "tie" as in std is easier to remember _1. you mistakenly renamed TWO sections to "C++ classes in Lua"
because 1) i hate typing and prefer to copy-paste the full working example when starting to work through tutorial, and 2) i feel myself much more confident when i see complete ready-to-run first example of any new technology |
I figure I'd do an in depth comment set too:
Otherwise, I agree with @Bulat-Ziganshin! It looks pretty good. |
Sol will push |
i propose to reduce code to the following:
(dropping abcval_equal and bark_equal) |
I can't find any tutorial about 'require' sol2 generated object in lua. static int init() {
sol::state lua;
lua.new_usertype<Foo>("Foo", ...);
return 0;
}
static int initalized = init(); I produce a My_Object.so with that and in lua: require ("My_Object") But it doesn't work, so there should be another way. |
@alkino Opening a new issue is encouraged so I can properly keep track of your reports. I will move your request to a new issue and respond there. |
The current README is pretty terse, and reading API reference is a not pleasant way to learn any library. I propose to kidnap manual from any competing library (kagaya, selene, lua-intf to name a few), made a few edits to identifiers (and list of supported compilers) and put it into README. You may even combine parts kidnapeed here and there. Later Sol-specific features may be added, but it will be a good start.
I believe that now, when you are released a major stable version, lack of step-by-step tutorial is main barrier to wider Sol2 acceptance.
The text was updated successfully, but these errors were encountered: