How to access standard string manipulation functions in Lua? - lua

I need some basic string operations, like sub-string, find string in string etc. I found a documentation of some standard functions for that: http://www.lua.org/manual/2.4/node22.html
But when I try it, I get an error:
input:29: attempt to call a nil value (global 'strfind')
Do I have to use require? Or are those methods contained in some object?

The link you posted is for Lua version 2.4. The latest version as of this post is Lua version 5.3. Make sure you are viewing the documentation for the version of Lua that you are using.
Lua 5.3 Reference

Related

Get argument passed to a function as a string literal?

Does Ruby provide any way of obtaining an argument passed to a function as a string literal?
In other words, if I have the following function...
def my_func(arg)
...
end
And I call my_func(obj.prop), I want to be able to obtain the following literal from within my_func...
"obj.prop"
I know Ruby can do some pretty funky things with metaprogramming, but I haven't found a way to be able to do this just yet.
This is not possible.
Ruby is a strict language, meaning that arguments get evaluated before being passed. IOW, all information about how the argument was produced is lost even before the method starts to execute.
There is no way to access the Ruby source code of a particular method, expression, or any other piece of code. In fact, since all Ruby implementations make it trivially easy to integrate with other languages (native extensions and FFI in YARV, mruby, and Rubinius, any JVM language in JRuby, ECMAScript in Opal, any CLI language in IronRuby, native extensions and Smalltalk in MagLev, and so on), there may not even be Ruby source code for a particular piece of code.
You want to obtain a string literal. Literals are part of a language's syntax, they don't even exist at runtime. Not only don't they exist at runtime, the very ideas of "runtime" and "literal" are fundamentally incompatible. Your request is not only impossible, it is non-sensical. There is no possible language, not even a hypothetical one, no possible world, in which your question would even make sense, let alone made to work.

passing Lua script from C++ to Lua

I want to pass a Lua script (code that Lua interpreter can process) from C++ and get the result back.
I looked online but could not find any example that would help me. I am able to call a Lua function from C++, but that requires you to create a file with Lua function.
Try using luaL_dostring, which loads and runs a given string.

In what version was the (...) introduced in Lua functions as arguments?

This as the most simple example as I can imagine:
function NewPrint(...)
print("printed:", ...)
end
NewPrint("Hi")
Please note, I haven't actually done Lua for a while, I might have missed some syntax.
As per the Lua.org documentation , it was Lua 5.1 .
Lua 5.1 was released on 21 Feb 2006. Its main new features were a new module system, incremental garbage collection, new mechanism for varargs, new syntax for long strings and comments, mod and length operators, metatables for all types, new configuration scheme via luaconf.h, and a fully reentrant parser.
The syntax in function definition has been introduced in Lua 5.0 (manual) Lua 2.5 (thanks to Luiz for correcting me), but it required to use arg table when you wanted to access those varargs. This has been fixed in Lua 5.1, which allowed to use ... notation for definitions and access to varargs.

Code Documentation in Dart

Do we have any code documentation syntax and tool support for generating Code Documentation out of Dart Application Code, something similar to Doxygen for C/C++. I prefer to use Markdown styled syntax than doxygen-syntax.
The DartDoc tool (which uses markdown) creates API documentation (as found at api.dartlang.org )
This describes the api reference for using DartDoc in your own code
The Readme.txt here, shows how you can format your code comments to generate API doc
///I am the beerclass
class BeerClass{
///this is a beer variable
String beername;
///this is a beer method
String get getBeer => "beer for the people";
}
Just go in the Darteditor: Tools->Generate Dartdoc. You get a new directory docs and you start index.html in your browser. Your class, variable and method have now documentation.

HMAC-SHA-512 implemention for ActionScript

As mentioned by the title, I would like to find an implementation for HMAC-SHA-512 written for ActionScript. I was able to find a library that provide HMAC-SHA-256 with other functions, however, I am looking for HMAC-SHA-512 specifically.
Thank you
Edit:
Or, since actionscript and javascript have the same origin, can some one port this javascript version into actionscript?
http://pajhome.org.uk/crypt/md5/sha512.html
Edit 2:
I already ported the code from javascript to actionscript. The code can be found in one of the answers in this question
Porting SHA-512 Javascript implementation to Actionscript
Checkout this library:
http://code.google.com/p/as3crypto/
Though only does:
SHA-256,SHA-224,SHA-1,MD5, and MD2
So I guess that doesn't answer your question.
But best Crypto library for actionscript I've seen.
The implementation you link to doesn't seem to be using any features that aren't supported by ActionScript 3. Just surround the whole thing with public class SHA512 { }, and prefix the first five functions with public.
Edit: You will also need to convert function int64 to it's own class (or possibly use Number, though I'm not sure if you will lose precision for 64-bit integers).
Just found all of SHA-2 (SHA-224, SHA-256, SHA-384, SHA-512) implemented at http://code.google.com/p/flame/. Also it provides HMAC implementation. Didn't try it yet but looks what you're looking for.

Resources